-->
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.  [ 2 posts ] 
Author Message
 Post subject: One-to-many only stores one-to-one
PostPosted: Wed Jul 25, 2007 3:06 am 
Newbie

Joined: Fri Jul 07, 2006 6:50 am
Posts: 2
Hi all,
I'm working with Hibrenate 3.2 GA, using annotations to declare Entities and its mappings. I'm having an undesired behavior using an unidirecitonal one-to-many relationship:


entity A has many entities B

where in entity A...

@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name="A_B")
@Sort(type = SortType.NATURAL)
public SortedSet<B> getBs() {
return this.bs;
}

public void addB(B b) {
this.bs.add(b);
}


The resulting behavior is that adding B entities in successive user requests, entities of type B are persisted in its table, but the join table only stores the last inserted relationship between A-B, resulting a one-to-one relationship.

In test, if to B entities are persisted during the same transaction, the result is the desired.

Any clue why this is happening?

thanks in advance,

Marc


Top
 Profile  
 
 Post subject: my fault
PostPosted: Thu Jul 26, 2007 11:43 am 
Newbie

Joined: Fri Jul 07, 2006 6:50 am
Posts: 2
mea culpa!

The problem was related to the fact I'm using a SortedSet of entities B, which implement the Comparable interface, where the compareTo only had two cases: bigger or smaller, but I didn't implemented the equals case.

This lead to a strange situation in the org.hibernate.action.CollectionUpdateAction, where it does...

persister.deleteRows( collection, id, session );
persister.updateRows( collection, id, session );
persister.insertRows( collection, id, session );

this deleteRows deleted all the entries from the first transaction, because it compared the existing ones when commiting the transaction with the ones loaded previously, and no one matched because compareTo was allways different!

Thanks for your patience ;-)

Marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.