我有一个表“学校”,带有和update trigger SchoolsHistory。当我通过简单的SQL语句更新时,触发器工作得很好。当Hibernate (通过Spring)更新对象时,我得到这个异常:
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation:
could not insert: [...]; uncategorized SQLException for SQL [the sql...]; SQL
state [null]; error code [0]; The statement must be executed before any
results can be obtained.; nested exception is
com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be
executed before any results can be obtained.当我禁用触发器时不会出现异常。此外,触发器发生在WebSphere上,而不是Tomcat上,所以可能与集群有关,等等。
发布于 2014-03-12 23:26:13
你的触发器代码有问题。如果您说在编辑器中手动输入SQL for insert语句并且它起作用,这意味着Hibernate使用不同的insert语句。您可以使用Hibernate属性show_sql
<property name="show_sql">true</property> 要查看您使用的sql语句和Hibernate produce之间的区别,请执行以下操作。有一件事很重要,hibernate在插入新记录时使用id列来设置主键。检查触发器代码或关闭触发器(如果可以解决问题)。
https://stackoverflow.com/questions/22355866
复制相似问题