浏览 6174 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2003-10-10
<class name="cn.mBig.experience.vo.SuffererVO" table="EXM_SUFFERER"> <id name="id" type="java.lang.Long" unsaved-value="0"> <column name="ID" sql-type="INT(10);"/> <generator class="identity"/> </id> <property name="name"> <column name="NAME" not-null="true" sql-type="VARCHAR(40);"/> </property> <bag name="Results" lazy="false" cascade="all"> <key> <column name="SUFFERER_ID"/> </key> <one-to-many class="cn.mBig.experience.vo.result.InspectResultVO"/> </bag> </class> <class name="cn.mBig.experience.vo.result.InspectResultVO" table="EXM_INSPECT_RESULT"> <composite-id> <key-property name="suffererId" type="java.lang.Long"> <column name="SUFFERER_ID" not-null="true" sql-type="INT(10);"/> </key-property> <key-property name="itemId" type="java.lang.Long"> <column name="ITEM_ID" not-null="true" sql-type="INT(10);"/> </key-property> </composite-id> <property name="result" type="java.lang.String"> <column name="RESULT" not-null="true" sql-type="VARCHAR(255);"/> </property> </class> 在删除SuffererVO的同时,按说应该delete from EXM_INSPECT_RESULT where SUFFERER_ID=? 但是hibernate 输出执行的却是 Hibernate: delete from EXM_SUFFERER_SUIT where SUFFERER_ID=? Hibernate: delete from EXM_SUFFERER_UNIT where SUFFERER_ID=? Hibernate: update EXM_INSPECT_RESULT set SUFFERER_ID=null where SUFFERER_ID=? 然后报错 2003-10-10 13:06:02 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 警告: SQL Error: 1062, SQLState: S1009 2003-10-10 13:06:02 net.sf.hibernate.util.JDBCExceptionReporter logExceptions 严重: Invalid argument value, message from server: "Duplicate entry '0-1' for key 1" 2003-10-10 13:06:02 net.sf.hibernate.JDBCException <init> 严重: Could not synchronize database state with session java.sql.BatchUpdateException: Invalid argument value, message from server: "Duplicate entry '0-1' for key 1" 请问这是怎么回事?一个字段不能既做外键又做联合主键吗? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2003-10-10
引用 Hibernate: delete from EXM_SUFFERER_SUIT where SUFFERER_ID=? Hibernate: delete from EXM_SUFFERER_UNIT where SUFFERER_ID=? 这两句sql中的表名从哪来的? 除了纯连接表,尽量少用复合主键。 |
|
返回顶楼 | |
发表时间:2003-10-10
完整得SuffererVO是这样的,忒长,所以截了
<class name="cn.mBig.experience.vo.SuffererVO" table="EXM_SUFFERER"> <id name="id" type="java.lang.Long" unsaved-value="0"> <column name="ID" sql-type="INT(10);"/> <generator class="identity"/> </id> <property name="name"> <column name="NAME" not-null="true" sql-type="VARCHAR(40);"/> </property> <property name="creationDate" type="timestamp" column="CREATIONDATE"/> <property name="description"> <column name="DESCRIPTION" sql-type="VARCHAR(255);"/> </property> <many-to-one name="creationUser" class="cn.mBig.experience.vo.UserVO" cascade="none" insert="false" update="false"> <column name="CREATION_USER_ID" sql-type="INT(10);"/> </many-to-one> <property type="java.lang.Long" name="creationUid"> <column name="CREATION_USER_ID" sql-type="INT(10);"/> </property> <property type="java.lang.Byte" name="state"> <column name="STATE" sql-type="TINYINT(1);"/> </property> <property type="java.lang.Byte" name="gender"> <column name="GENDER" sql-type="TINYINT(1);"/> </property> <many-to-one name="application" class="cn.mBig.experience.vo.ApplicationVO" cascade="none" insert="false" update="false"> <column name="APPLICATION_ID" sql-type="INT(10);"/> </many-to-one> <property type="java.lang.Long" name="applicationId"> <column name="APPLICATION_ID" sql-type="INT(10);"/> </property> <property name="address"> <column name="ADDRESS" sql-type="VARCHAR(50);"/> </property> <property name="idCard"> <column name="ID_CARD" sql-type="VARCHAR(30);"/> </property> <property name="phone"> <column name="PHONE" sql-type="VARCHAR(40);"/> </property> <property name="birthday" type="date" column="BIRTHDAY"/> <bag name="suits" lazy="true" table="EXM_SUFFERER_SUIT" cascade="save-update"> <key> <column name="SUFFERER_ID" sql-type="INT(10);"/> </key> <many-to-many class="cn.mBig.experience.vo.SuitVO"> <column name="SUIT_ID" sql-type="INT(10);"/> </many-to-many> </bag> <bag name="units" lazy="true" table="EXM_SUFFERER_UNIT" cascade="save-update"> <key> <column name="SUFFERER_ID" sql-type="INT(10);"/> </key> <many-to-many class="cn.mBig.experience.vo.UnitVO"> <column name="UNIT_ID" sql-type="INT(10);"/> </many-to-many> </bag> <bag name="Results" lazy="false" cascade="all"> <key> <column name="SUFFERER_ID"/> </key> <one-to-many class="cn.mBig.experience.vo.result.InspectResultVO"/> </bag> </class> |
|
返回顶楼 | |
发表时间:2003-10-10
试试用itemId作为cn.mBig.experience.vo.result.InspectResultVO的id,不要用composite-id。
另 bag设为inverse="false"(默认)效率是很低的。 |
|
返回顶楼 | |
发表时间:2003-10-10
itemId 不是唯一标识啊,
实际上InspectResultVO有点像 ItemVO和SuffererVO的多对多的映射表,但是多一个字段存储数值 |
|
返回顶楼 | |