-->
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: find(class, object) has side effects on the object
PostPosted: Fri Aug 24, 2012 2:19 pm 
Newbie

Joined: Fri Aug 24, 2012 1:46 pm
Posts: 1
Dear groupmembers,
Due to certain reasons, i have to (or thougth that i have to) find out if an entity is already stored in the db.
If true, i will merge the entity, if not, other things shall happen.
My entity has a list of other objects, annotaned (one directional):
@OneToMany
private List<Sample> samples;



I was very surprised to find the following hibernate (4.1.3) behaviour:

EntityManager em = emf.createEntityManager();

try{
EntityTransaction tx = em.getTransaction();
tx.begin();
//test that data are ok
for (ISample s: ss.getSamples()){
debug(s.getSampleName());
//here my entity ss has various samples in the list
}
SubSet ss2=em.find(SubSet.class,ss);
//SubSet ss2=(SubSet) ((Session)em.getDelegate()).get(SubSet.class,(SubSet)ss); //same is true for pure hibernate
if (ss2==null){
//do something else
}
else{
for (ISample s: ss.getSamples()){
debug(s.getSampleName()); // my samples are GONE !!! The list is empty !
}
}

....
In summary: if i perform a simple find or get action, the object used for this as provider for the ID is affected seriously
So my question is:
how can i test for the existence of an object in the database without side-effects?

Maybe a simple mis-configuration issue (i`m hibernate novice) but i lost too much time on it and did not find anything by google so any explanation is highly appreciated
Thanks,
retep


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.