-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Unique key constraint problem
PostPosted: Wed Mar 24, 2004 2:10 am 
Beginner
Beginner

Joined: Wed Mar 17, 2004 12:44 am
Posts: 25
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.