title: Hibernate not working with Sql Server 2008
body: <p>I am Hibernate noob. I recently started to learn Hibernate. 
  I am following a tutorial...but I am lost now. I have been trying to solve this problem...</p>
  
  <p><b> hibernate.cfg.xml </b> </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  
  &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" 
  &gt;
  
  &lt;hibernate-configuration&gt;
  
  
      &lt;session-factory&gt;
  
          &lt;property name="hibernate.dialect" &gt;
  org.hibernate.dialect.SQLServer2008Dialect
          &lt;/property&gt;
  
          &lt;property name="hibernate.connection.driver_class" &gt;
  com.microsoft.sqlserver.jdbc.SQLServerDriver
          &lt;/property&gt;
  
          &lt;property name="hibernate.connection.username" &gt;
  not required
          &lt;/property&gt;
  
          &lt;property name="hibernate.connection.password" /&gt;
          &lt;property name="hibernate.connection.url" &gt;
  jdbc:sqlserver://localhost;databaseName=hibernate;integratedSecurity=false;
          &lt;/property&gt;
  
          &lt;property name="hibernate.cache.use_query_cache" &gt;
  true
          &lt;/property&gt;
  
          &lt;property name="hibernate.cache.region_prefix" &gt;
  hibernate.test
          &lt;/property&gt;
  
          &lt;property name="hibernate.jdbc.use_streams_for_binary" &gt;
  true
          &lt;/property&gt;
  
          &lt;property name="hibernate.jdbc.batch_size" &gt;
  0
          &lt;/property&gt;
  
          &lt;property name="hibernate.max_fetch_depth" &gt;
  3
          &lt;/property&gt;
  
          &lt;property name="hibernate.hbm2ddl.auto" &gt;
  create-drop
          &lt;/property&gt;
  
          &lt;property name="hibernate.generate_statistics" &gt;
  true
          &lt;/property&gt;
  
          &lt;property name="hibernate.cache.region.factory_class" &gt;
  org.hibernate.testing.cache.CachingRegionFactory
          &lt;/property&gt;
  
          &lt;mapping class="com.hibernate.dto.UserDetails" /&gt;
  
  
  
          &lt;class-cache
              class="org.hibernate.ejb.test.item"
              usage="read-write" /&gt;
  
          &lt;collection-cache
              collection="org.hibernate.ejb.test.Item.distributors"
              region="RegionName"
              usage="read-write" /&gt;
  
          &lt;event type="pre-insert" /&gt;
      &lt;/session-factory&gt;
  
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><b> UseDetails.java</b></p>
  
  <pre><code>package com.hibernate.dto;
  
  import javax.persistence.Entity;
  import javax.persistence.Id;
  
  @Entity
  public class UserDetails {
  
  @Id
      private int userId;
      private String userName;
  
  
      public int getUserId() {
          return userId;
      }
      public void setUserId(int userId) {
          this.userId = userId;
      }
      public String getUserName() {
          return userName;
      }
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
  
  
  
  }
  </code></pre>
  
  <p><b> hibernateTest.java </b></p>
  
  <pre><code>package com.hibernate.dto;
  
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  import org.hibernate.service.ServiceRegistryBuilder;
  
  public class HibernateTest {
  
      public static void main(String[] args) {
  
          UserDetails user = new UserDetails();
  
          user.setUserId(1);
          user.setUserName("ahmed");
  
  
  
          SessionFactory sessionfact = new Configuration().configure()
                  .buildSessionFactory();
  
          Session session = sessionfact.openSession();
          session.beginTransaction();
          session.save(user);
          session.getTransaction().commit();
          session.close();
  
      }
  
  }
  </code></pre>
  
  <p>now when I try to run it. I get this following error every time...but I am still unsure what it is point at to?
  Please help me...</p>
  
  <p><b> error log </b></p>
  
  <pre><code>Aug 25, 2012 10:27:40 PM org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
  Aug 25, 2012 10:27:40 PM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.1.6.Final}
  Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  Aug 25, 2012 10:27:40 PM org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  Exception in thread "main" org.hibernate.MappingException: Cannot cache an unknown entity: org.hibernate.ejb
      at org.hibernate.cfg.Configuration.applyCacheConcurrencyStrategy(Configuration.java:2212)
      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1368)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1733)
      at com.hibernate.dto.HibernateTest.main(HibernateTest.java:25)
  </code></pre>
  
  <p>I looked into hibernate jar but couldn't find the <code>org.hibernate.ejb.test.item</code></p>
  
  <p><b> UPDATE </b> </p>
  
  <p>now I get these errors </p>
  
  <pre><code>Aug 25, 2012 11:51:06 PM org.hibernate.annotations.common.Version &lt;clinit&gt;
  INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
  Aug 25, 2012 11:51:06 PM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.1.6.Final}
  Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Configuration configure
  INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
  Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Configuration getConfigurationInputStream
  INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
  Aug 25, 2012 11:51:06 PM org.hibernate.cfg.Configuration doConfigure
  INFO: HHH000041: Configured SessionFactory: null
  Aug 25, 2012 11:51:06 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
  Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000115: Hibernate connection pool size: 20
  Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000006: Autocommit mode: false
  Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000401: using driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] at URL [jdbc:sqlserver://localhost;databaseName=hibernate;integratedSecurity=false;]
  Aug 25, 2012 11:51:07 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
  INFO: HHH000046: Connection properties: {user=not required, password=****}
  Aug 25, 2012 11:51:07 PM com.microsoft.sqlserver.jdbc.SQLServerConnection &lt;init&gt;
  SEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
  Aug 25, 2012 11:51:07 PM org.hibernate.dialect.Dialect &lt;init&gt;
  INFO: HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
  Aug 25, 2012 11:51:07 PM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
  INFO: HHH000422: Disabling contextual LOB creation as connection was null
  Aug 25, 2012 11:51:07 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
  INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
  Aug 25, 2012 11:51:07 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
  INFO: HHH000397: Using ASTQueryTranslatorFactory
  Exception in thread "main" org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.testing.cache.CachingRegionFactory]
      at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:410)
      at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:264)
      at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279)
      at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1744)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)
      at com.hibernate.dto.HibernateTest.main(HibernateTest.java:21)
  Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.testing.cache.CachingRegionFactory]
      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
      at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:393)
      ... 6 more
  Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.testing.cache.CachingRegionFactory
      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:264)
      at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
      ... 7 more
  </code></pre>
  
  <p>I added <code>@Table (name = "hibernate")</code> along with <code>@Entity</code> too.</p>