I'm facing a problem in one to many mapping in Hibernate 3!Hope somebody can help me!!
Consider this One to many Mapping
Participant.hbm.xml
<set
name="participantTypes"
table="ParticipantParticipantType"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="PARTICIPANTID"
>
</key>
<one-to-many
class="ParticipantParticipantTypeDTO"
/>
</set>
######
Participant Fields- PARTICIPANTID,Name
ParticipantParticipantType fields -ID,PARTICIPANTID,PARTICIPANTTYPEID
#######
When I try to Add a new Participant (with inverse=true) with a set of
ParticipantParticipantTypes; Participant is being added properly with
PARTICIPANTID say a 200 (System generated ) .But entry in
ParticipantParticipantType table has PARTICIPANTID 0 not 200 .When i
give "inverse=false" It is working properly!!
But now its giving a new problem..!!Suppose I want to remove a
ParticipantParticipantType i deleted it from the set but its showing
exception given below
####################
org.hibernate.exception.ConstraintViolationException: could not delete
collection rows:
[com.security.dto.ParticipantDTO.participantTypes#1090]
at.....
Caused by: COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT]
SQL0407N Assignment of a NULL value to a NOT NULL column
"TBSPACEID=2, TABLEID=51, COLNO=1" is not allowed. SQLSTATE=23502
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown
Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(Unknown
Source)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.execute2(Unknown Source)
at COM.ibm.db2.jdbc.app.DB2PreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.collection.AbstractCollectionPersister.deleteRows(AbstractCollectionPersister.java:961)
#######################
The irony is that if I give "inverse=true" This will
happen Perfectly!
|