-->
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.  [ 5 posts ] 
Author Message
 Post subject: Convert a entity from one session to another session
PostPosted: Thu Jun 23, 2005 5:49 am 
Newbie

Joined: Wed Jun 15, 2005 8:51 am
Posts: 11
Hi,

I like to load an entity from one database and then insert it into another database.

I created 2 sessions (session and sessionbuffer).
I load an entity from session.
Then I make this entity persistent in sessionbuffer.

But that don't work, because of this message:
Quote:
object already associated with session: ....


I thought that my entity was a POJO, so this could just be done:
Code:
...
Criteria criteria = session.createCriteria(Probprod.class).add(
                    Restrictions.eq("bundnr1", bundnr1)).addOrder(
                    Property.forName("enddat").desc());
....
Transaction tx = sessionBuffer.beginTransaction();
sessionBuffer.persist(criteria.list().get(0));
...
tx.commit();
....



Is there a correct and easy way of doing this???

Thanx in advance,
Marcel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 6:04 am 
Newbie

Joined: Wed Jun 15, 2005 8:51 am
Posts: 11
I'm using Hibernate 3.0.5.

session is a Oracle database
sessionBuffer is a HSQL database


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 6:21 am 
Beginner
Beginner

Joined: Wed Apr 13, 2005 10:34 am
Posts: 38
I'm not sure, but you could try to evict the object from the session first.

Code:
Object o = criteria.list().get(0);
session.evict(o);
sessionBuffer.persist(o);


regards,

heiko


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 6:34 am 
Newbie

Joined: Wed Jun 15, 2005 8:51 am
Posts: 11
Looked good, but...

Now session tries to insert the entity again (instead of sessionBuffer).
And of course is that not what I wanted (I get a unique constraint violation from Oracle).

Any other help?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 10:25 am 
Newbie

Joined: Wed Jun 15, 2005 8:51 am
Posts: 11
I really don't understand why this happens...

I say persist in the sessionbuffer, but hibernate tries to do this in the session.

WHY???


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