hibernate 问题,中间表的数据无法插入
我在执行comUserMag.saveUser(comUser);保存操作时候,出现中间表不能够保存。log如下:insertintodbo.COM_USER(UserN...
我在执行 comUserMag.saveUser(comUser); 保存操作时候,出现中间表不能够保存。log如下:
insert into dbo.COM_USER (UserName, LoginName, UserPassword, IsManager, Orders, Isuse, Mobile, Telphone, Extension, Fax, Email, Address, Code, Other, Remark, Status, Gonghao, CREATE_TIME, fdepartid, PUserId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into dbo.COM_USER (UserName, LoginName, UserPassword, IsManager, Orders, Isuse, Mobile, Telphone, Extension, Fax, Email, Address, Code, Other, Remark, Status, Gonghao, CREATE_TIME, fdepartid, PUserId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2013-10-12 10:15:05 org.hibernate.jdbc.util.SQLStatementLogger logStatement
良好: delete from com_userdept where fuserid=?
Hibernate: delete from com_userdept where fuserid=?
2013-10-12 10:15:05 org.hibernate.jdbc.util.SQLStatementLogger logStatement
良好: insert into com_userdept (fuserid, pid, fdepartID) values (?, ?, ?)
Hibernate: insert into com_userdept (fuserid, pid, fdepartID) values (?, ?, ?)
2013-10-12 10:15:05 org.hibernate.util.JDBCExceptionReporter logExceptions
警告: SQL Error: 544, SQLState: S0001
2013-10-12 10:15:05 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'COM_USERDEPT' 中的标识列插入显式值。
2013-10-12 10:15:05 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
严重: Could not synchronize database state with session
<list name="userDepts" table="com_userdept" lazy="false">
<key column="fuserid"/>
<list-index column="pid"/>
<composite-element class="com.gwideal.oa.user.entity.ComUserDept">
<many-to-one name="comDept" column="fdepartID" class="com.gwideal.oa.user.entity.ComDept" />
</composite-element>
</list>
这个是hibernate文件,对中间表的关联 展开
insert into dbo.COM_USER (UserName, LoginName, UserPassword, IsManager, Orders, Isuse, Mobile, Telphone, Extension, Fax, Email, Address, Code, Other, Remark, Status, Gonghao, CREATE_TIME, fdepartid, PUserId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into dbo.COM_USER (UserName, LoginName, UserPassword, IsManager, Orders, Isuse, Mobile, Telphone, Extension, Fax, Email, Address, Code, Other, Remark, Status, Gonghao, CREATE_TIME, fdepartid, PUserId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2013-10-12 10:15:05 org.hibernate.jdbc.util.SQLStatementLogger logStatement
良好: delete from com_userdept where fuserid=?
Hibernate: delete from com_userdept where fuserid=?
2013-10-12 10:15:05 org.hibernate.jdbc.util.SQLStatementLogger logStatement
良好: insert into com_userdept (fuserid, pid, fdepartID) values (?, ?, ?)
Hibernate: insert into com_userdept (fuserid, pid, fdepartID) values (?, ?, ?)
2013-10-12 10:15:05 org.hibernate.util.JDBCExceptionReporter logExceptions
警告: SQL Error: 544, SQLState: S0001
2013-10-12 10:15:05 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'COM_USERDEPT' 中的标识列插入显式值。
2013-10-12 10:15:05 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
严重: Could not synchronize database state with session
<list name="userDepts" table="com_userdept" lazy="false">
<key column="fuserid"/>
<list-index column="pid"/>
<composite-element class="com.gwideal.oa.user.entity.ComUserDept">
<many-to-one name="comDept" column="fdepartID" class="com.gwideal.oa.user.entity.ComDept" />
</composite-element>
</list>
这个是hibernate文件,对中间表的关联 展开
1个回答
展开全部
你好,你贴的信息根本不全没法有针对性的去排查,
但是有一条可能有意义的信息:“严重: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'COM_USERDEPT' 中的标识列插入显式值”。
估计你用的是SQL SERVER数据库,很可能出现你所的这个异常的原因是因为你在数据库的表'COM_USERDEPT' 有个字段(或许是主键吧)是设计成自增长的方式,而你在程序里面insert的时候又为该字段赋值了,
解决方案:
1、在SQL SERVER中执行 SET IDENTITY_INSERT COM_USERDEPT ON;
2、在程序中去掉自增长字段的赋值。
希望对你有帮助
但是有一条可能有意义的信息:“严重: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'COM_USERDEPT' 中的标识列插入显式值”。
估计你用的是SQL SERVER数据库,很可能出现你所的这个异常的原因是因为你在数据库的表'COM_USERDEPT' 有个字段(或许是主键吧)是设计成自增长的方式,而你在程序里面insert的时候又为该字段赋值了,
解决方案:
1、在SQL SERVER中执行 SET IDENTITY_INSERT COM_USERDEPT ON;
2、在程序中去掉自增长字段的赋值。
希望对你有帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询