Hello,
Facing a unique constraint problem with a hibernate table..
Table Structure : (only concered fields are given)
Subject :
- ID
Subject_Categories :
- ID
- Subject_ID (FK)
- Category_ID (FK)
- TimeStamp
Categories :
- ID
- Category_Name
XMLs :
Subject.hbm.xml : Subject
- <set name="subjectCategories" lazy="true" cascade="all" table="Subject_Categories" >
<key column="Subject_ID" />
<one-to-many class="SubjectCategories" />
</set>
Subject_Categories.hbm.xml : Subject_Categories
- <timestamp name="timestamp" column="TIMESTAMP"/>
<many-to-one name="subject" class="Subject" column="Subject_ID"/>
<many-to-one name="category" class="Categories" column="Category_ID"/>
Categories.hbm.xml : Categories
- <property name="name" column="APHASIA_NAME" type="java.lang.String" length="32" />
Constraints :
- Subject_Categories
- Joint Unique constraint on Subject_Id and Category_Id
Exception :
ERROR [http8080-Processor4] JDBCExceptionReporter.logExceptions(46) | ORA-00001: unique constraint (STS.SYS_C001857) violated
WARN [http8080-Processor4] JDBCExceptionReporter.logExceptions(38) | SQL Error: 1, SQLState: 23000
ERROR [http8080-Processor4] JDBCExceptionReporter.logExceptions(46) | ORA-00001: unique constraint (STS.SYS_C001857) violated
ERROR [http8080-Processor4] JDBCException.<init>(38) | Could not execute JDBC batch update
java.sql.SQLException: ORA-00001: unique constraint (STS.SYS_C001857) violated
Code :
Set subjectCategoriesSet = new HashSet();
subject.setSubjectCategoriesSet(null); // To delete all the existing mappings
while(<more ids>) {
SubjectCategories subjectCategories = new SubjectCategories();
subjectCategories.setSubject(subject); // Old subject object
subjectCategories.setCategory(new Category(id)); // Passing the ID
subjectCategoriesSet.add(subjectCategories);
}
subject.setSubjectCategoriesSet(subjectCategoriesSet);
When the subject domain object is generated I get a java.util.Set subjectCategories. In the code I am trying to insert multiple values in this set and getting the error. However, I don't think something not unique is being inserted. Are the mappings correct ?
nitin
|