我正在添加对我们的应用程序的支持以使用SQL Server(它已经适用于MySQL)并且在几次成功之后遇到了Hibernate / JDBC查询问题。在这种情况下,数据库开始时是完全空的。我们将数据加载到数据库时会出现问题。
再次,这适用于MySQL。
这是hibernate sql语句(挂在最后一个条目上):
Hibernate: select permission0_.dbID as dbID1_73_, permission0_.Created as Created2_73_, permission0_.dbVersion as dbVersio3_73_, permission0_.Origin as Origin4_73_, permission0_.Updated as Updated5_73_, permission0_.Entity as Entity6_73_ from Permission permission0_ where permission0_.Entity=?
Hibernate: select permission0_.dbID as dbID1_73_, permission0_.Created as Created2_73_, permission0_.dbVersion as dbVersio3_73_, permission0_.Origin as Origin4_73_, permission0_.Updated as Updated5_73_, permission0_.Entity as Entity6_73_ from Permission permission0_ where permission0_.Entity=?
Hibernate: select next value for hibernate_sequence
Hibernate: insert into Permission (Created, dbVersion, Origin, Updated, Entity, dbID) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into Permission_Operations (Permission_id, T_element) values (?, ?)
Hibernate: select permission0_.dbID as dbID1_73_, permission0_.Created as Created2_73_, permission0_.dbVersion as dbVersio3_73_, permission0_.Origin as Origin4_73_, permission0_.Updated as Updated5_73_, permission0_.Entity as Entity6_73_ from Permission permission0_ where permission0_.Entity=?
Hibernate: select permission0_.dbID as dbID1_73_, permission0_.Created as Created2_73_, permission0_.dbVersion as dbVersio3_73_, permission0_.Origin as Origin4_73_, permission0_.Updated as Updated5_73_, permission0_.Entity as Entity6_73_ from Permission permission0_ where permission0_.Entity=?
当我使用SQL Server Studio时,我将最后一个查询看作State = SUSPENDED和Wait = LCK_M_S(见下图)。
最后一个查询永远不会完成/返回。我让它运行了12个小时。我使用javax.persistence.query.timeout提示添加了60秒的超时,因为它没有永久挂起。
配置:
我的persistence.xml:
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.id.new_generator_mappings" value="true" />
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="25" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.validate" value="true" />
<!-- Tried with and without this:
<property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1" />
-->
我还以编程方式设定了这些值:
hibernate.connection.driver_class : com.microsoft.sqlserver.jdbc.SQLServerDriver
hibernate.connection.password : <MASKED>
hibernate.connection.url : jdbc:sqlserver://sqlserver:1433;databaseName=xxx_test0
hibernate.connection.username : xxx
hibernate.dialect : org.hibernate.dialect.SQLServer2012Dialect
hibernate.show_sql : true
答案 0 :(得分:0)
我弄明白了这个问题。我没有在插入之后但在下一次选择之前进行提交。出于某种原因,MySQL对此很好,但SQL Server想要等待。
在完成所有插入后添加提交解决了问题。