-->
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.  [ 7 posts ] 
Author Message
 Post subject: Interesting one..
PostPosted: Thu Mar 25, 2004 2:45 pm 
Beginner
Beginner

Joined: Wed Mar 17, 2004 12:44 am
Posts: 25
Hello folks,

So 3 tables and their mappings .. finding problem removing the records from table..

Subject
ID (SEQ)
OtherSubjectDetails

SubjectAphasia
ID (SEQ)
Subject_Id
Aphasia_Id

Aphasia
ID (SEQ)
Name

Mappings :
Subject.hbm.xml
===========
<set name="aphasiaTypes" inverse="true" cascade="all>
<key column="SUBJECT_ID"/>
<one-to-many class="com.imc.sts.domain.the.SubjectAphasia" />
</set>

SubjectAphasia.hbm.xml
================
<many-to-one name="parentSubject" class="com.imc.sts.domain.the.Subject" column="SUBJECT_ID"/>
<many-to-one name="aphasia" class="com.imc.sts.domain.Aphasia" column="APHASIA_ID" cascade="all" />

Aphasia.hbm.xml
===========
<property name="name" column="APHASIA_NAME" type="java.lang.String" length="32" />

Using a Set in Subject domain object I can add the values to SubjectAphasia table. But in edit when I get the old values and make some changes to the set and add them again to the domain object they are not being reflected to the DB. I doubt if there is any error in the mappings. If anybody needs code.. I will send it ..

Thanx,

nitin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 2:56 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Do you have good equals() and hashCode() methods in SubjectAphasia?

Also, since you have a surrogate id in the SubjectAphasia table, why not try an idbag instead of a set?


Top
 Profile  
 
 Post subject: source code..
PostPosted: Thu Mar 25, 2004 3:20 pm 
Beginner
Beginner

Joined: Wed Mar 17, 2004 12:44 am
Posts: 25
thanx greg.. yeah I do have proper implementation of equals and hashcode. I modified the domain object for equals and hashcode methods.

subjectAphasiaTypesSet.clear();

for(int i = 0; i < aphasiaTypes.length; i++) {
log.info("aphasiaTypes[" + i + "] = " + aphasiaTypes[i]);
log.info("aphasia object = " + tDao.getAphasiaById(aphasiaTypes[i]));

SubjectAphasia subjectAphasia = new SubjectAphasia();
subjectAphasia.setParentSubject(subject);
subjectAphasia.setAphasia(tDao.getAphasiaById(aphasiaTypes[i]));

log.info("Subject Aphasia = " + subjectAphasia);
subject.getAphasiaTypes().add(subjectAphasia);
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 3:33 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
look at inverse="true" meaning, http://www.hibernate.org/155.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 3:33 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Oops. Didn't notice that you have inverse="true" on the set. See http://www.hibernate.org/155.html, especially the following line: "Changes made to the association on the side of the inverse="true" are not persisted in DB."


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 3:38 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
and of course look at what inverse="false" will do... :)


Top
 Profile  
 
 Post subject: Tried both ways
PostPosted: Fri Mar 26, 2004 12:49 am 
Beginner
Beginner

Joined: Wed Mar 17, 2004 12:44 am
Posts: 25
I have tried it both ways.. keeping inverse="true/false" still not working

nitin


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

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.