SQL Server Windows身份验证和休眠

时间:2017-03-29 12:21:14

标签: sql-server hibernate windows-authentication hibernate-entitymanager

尝试使用Hibernate 4.3连接到使用Windows身份验证的SQL Server,我得到了:

"没有EntityManager的持久性提供程序名为instanceTest"

我已经加载了sqljdbc_auth.dll库并使用了这个url:

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

我用来创建实体管理器工厂的参数是:

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");

我错过了什么?也许是dll没有加载?这一行引发了错误:

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

数据库配置正确,我通过Windows身份验证与SQL Server Management连接。此外,在之前的测试中,我实现了使用没有休眠的驱动程序创建数据库。

提前致谢。

2 个答案:

答案 0 :(得分:0)

沿着这些,添加以下属性

properties.put("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");

答案 1 :(得分:0)

解决!

比我想象的简单得多。当我编译maven项目时,我无意中删除了persistence.xml文件。这就是原因,因为它从来没有在战争中找到持久性提供者。

相关问题