-->
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.  [ 2 posts ] 
Author Message
 Post subject: Need support for shared references/shared collections
PostPosted: Wed Apr 16, 2008 11:59 am 
Newbie

Joined: Wed Apr 16, 2008 11:23 am
Posts: 2
Hibernate version:
Hibernate 3.2.2ga


Hi all,

imaging the following model:

1 Person has n Versions of a Person

Person 1 - n PersonVersion


1 PersonVersion has one Version of an Address

PersonVersion 1 - N Address

1 Address has n Versions of an Address

Address 1 - n AddressVersion

The attributes of e.g. a person are immutable.
If an attribute must be changed it results in a new PersonVersion.

The new PersonVersion is the same one as the old, except for the changed attribute.
So the "new" PersonVersion has the same Address with the same AddressVersions.

The PersonVersion is only a clone. The properties Address and List<AddressVersion> are a copy of the original (same reference).

If i save the Person-Object (persist the changes) I get an exception:
"Found shared references to a collection".

Is there any possibility to only insert the new PersonVersion but not to affect the referenced collections, cause the referenced collections contain the same items (same means the references are equal)

Kind regards,

sebastian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 16, 2008 12:37 pm 
Newbie

Joined: Wed Apr 16, 2008 11:23 am
Posts: 2
oops..a little bit confusing, not? :)

Simple Example

Code:
class Person{
    private List<Address> addy;
    // getters and setters for addy
}

class Address{
   private String street;
   // getters and setters

}


and now..

Code:
List<Address> addresses = new ArrayList<Address>();
addresses.add(new Address());
addresses.add(new Address());

Person p1 = new Person();
p1.setAddy(addresses);

Person p2 = new Person();
p2.setAddy(addresses);

getSession().save(p1);
getSession().save(p2);


All references are mapped with cascade="all".

How to do this?

Kind regards

Sebastian


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