Search code examples
sql-serverhibernatewindows-authenticationhibernate-entitymanager

SQL Server Windows Authentication and Hibernate


Trying to connect, using Hibernate 4.3, to SQL Server with Windows Authentication, i'm getting a:

"No Persistence provider for EntityManager named instanceTest"

I have loaded the sqljdbc_auth.dll library and im using this url:

jdbc:sqlserver://localhost:1433;databaseName=WIN_AUTHDB;integratedSecurity=true

The parameters which i am using to create the entity manager factory are:

properties.put("background-validation", "true");
properties.put("hibernate.c3p0.idle_test_period", "3600");
properties.put("hibernate.hbm2ddl.auto", "update");
properties.put("hibernate.max_fetch_depth", "3");
properties.put("hibernate.connection.driver_class", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
properties.put("hibernate.connection.url","jdbc:sqlserver://localhost:1433;databaseName=WIN_AUTHDB;integratedSecurity=true");

Im missing something? Maybe is the dll not loaded? The error is thrown at this line:

Persistence.createEntityManagerFactory("instanceTest", initProperties(properties));

The database is correctly configured, i have connected through Windows Authentication with the SQL Server Management. Also, in a previous test, i achieved to create a database using the driver without hibernate.

Thanks in advance.


Solution

  • Resolved!

    Much more simple than I thought. When I was compiling the maven project, i was unintentionally deleting the persistence.xml file. Thats the reason because it never found the persistence provider at the war.