-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to save this object using only 1 transaction?
PostPosted: Wed May 16, 2007 12:28 pm 
Newbie

Joined: Mon May 14, 2007 9:58 pm
Posts: 7
Location: Bahia / Brasil
Please, I have 3 classes of objects.

They are parents from another. Example:

"A" is a conteiner of "B", and "B" set "C", like this:

Code:
A.add(B);
B.set(C);


So, I'm trying to save "A" Object, but Hibernate tell me this is not possible, because there are two or more "C" object with the same identifier.

The exception mesage is:

Code:
Caused by: com.expert.dao.ExpertDaoException: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.expert.pojos.Conta#25]


Where "com.expert.pojos.Conta" above is my "C" object.

I want add "A" object iside only 1 transaction. I think it will be very inconvenience if I have to do a new transaction to each "B" object I want to save in my data base.

Is there a more easy way to save "A" object in an only and unique session opened???

Thank you.

Cristiano


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 1:10 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Can you show your mapping files?

I suspect you have to set inverse=true in your bidirectional links.

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 6:08 am 
Newbie

Joined: Mon May 14, 2007 9:58 pm
Posts: 7
Location: Bahia / Brasil
nope

I'm not usint inverse = true

But I found a way to save C object too.

The exception was occurred because there are two or more C object with the same ID in session.

I'm using this way now:

Code:
while (itr.hasNext() {
  B a = (B)itr.next();
  B.setC( serviceC.get(C.getId()) ); // <-- I added this line
  serviceB.save(B);
  A.add(B);
  serviceA.save(A);
}

serviceA.save(A);



It's work now.

Thank you.


Top
 Profile  
 
 Post subject: how to save this object using only 1 transaction?
PostPosted: Thu May 17, 2007 9:34 am 
Beginner
Beginner

Joined: Wed Apr 18, 2007 6:17 pm
Posts: 49
Location: Dominican Republic
hello guys, i believe himawan, that it would be problems with the inverse=true if C where a collection in B but it's just a single many-to-one, i think that it's a problem with cascade. I know that you can solve this problem in a more elegant way without:

Quote:
B.setC( serviceC.get(C.getId()) ); // <-- I added this line


Try to play with cascade and let us know how it went.


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