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
|