-->
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.  [ 3 posts ] 
Author Message
 Post subject: Same Objectinstance for Embedded Objects in different Entity
PostPosted: Wed Oct 27, 2010 9:35 am 
Newbie

Joined: Wed Jan 09, 2008 11:31 am
Posts: 3
I do use the embedded class TimePeriod(validFrom, validTo) in diffrent Business entities. These entities are mapped to different tables. Loading multiple entities in one session creats only one TimePeriode objct for all off these classes if they have the same time periode. If I change the time periode of one entity using getTimePeriod().setValidFrom(...) the valid from property is changed for all Business entities. After flush() many of the validFrom colums I loaded before are changed although I wanted to change only one.

Does anyone know how I can avoid getting only one Object for all the TimePeriods ??

Code:
   @Type(type = "at.itsv.lea.be.cut.TimePeriodCompositUserType")
   @Columns(columns = { @Column(name = "gueltigVon", nullable=true),
         @Column(name = "gueltigBis", nullable=true) })
   @Embedded
   private TimePeriod zeitraum;


Code:
@Embeddable
public class TimePeriod implements java.io.Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 1L;

   private java.util.Date gueltigVon = null;

   private java.util.Date gueltigBis = null;


Top
 Profile  
 
 Post subject: Re: Same Objectinstance for Embedded Objects in different Entity
PostPosted: Wed Nov 03, 2010 6:45 am 
Newbie

Joined: Wed Jan 09, 2008 11:31 am
Posts: 3
I do know a solution for the problem now.

We have created a tree of entities with one TimePeriod object for all of them.
With entityManager.flush() they are stored to the database. Reading them afterwards does not access the database but gets the objects from the cache where all the TimePeriodeObjects are the same instance.

entityManage.flush() + entityManager.clear() solves the problem.


Top
 Profile  
 
 Post subject: Re: Same Objectinstance for Embedded Objects in different Entity
PostPosted: Wed Nov 03, 2010 12:05 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2010 6:12 pm
Posts: 29
Quote:
I do use the embedded class TimePeriod(validFrom, validTo) in diffrent Business entities.


AFAIK, this is unsupported by the JPA spec and possibly by Hibernate as well. The spec clearly states:

Quote:
Embedded objects belong strictly to their owning entity, and are not sharable across persistent entities. Attempting to share an embedded object across entities has undefined semantics.


You may have to rethink your design on this one.


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