My application is working fine withe hypersql in memory database however, When I have tried to move to MSSQL the application is throwing exceptions.
I have added dependency of the mssql in POM file:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.4.0.jre8</version>
<scope>test</scope>
</dependency>
The following NOT-WORKING code for mssql in hibernate xml file:
<hibernate-configuration>
<session-factory>
<property name="hibernate.archive.autodetection">class,hbm</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.username">ABCD</property>
<property name="hibernate.connection.password">0000</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databasename=c1;</property>
<property name="hibernate.hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
The following WORKING code for hypersql in hibernate xml file:
<hibernate-configuration>
<session-factory>
<property name="hibernate.archive.autodetection">class,hbm</property>
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.url">jdbc:hsqldb:mem:howtodoinjava</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.acquire_increment">1800</property>
<property name="hibernate.c3p0.max_statements">150</property>
</session-factory>
</hibernate-configuration>
Application throws the exceptions like:
Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
CAUSED BY:
java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.microsoft.sqlserver.jdbc.SQLServerDriver]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getSessionFactory'
Your connection setting is linked to the incorrect driver.
Point it to the same one you imported in your pom.xml (
<groupId>com.microsoft.sqlserver</groupId>)