Hi,
This is from the Hibernate documentation:
Quote:
Values have no independent identity, so they cannot be shared by two entities or collections
Does this really mean that, if I want to persist a copy of an object, say of class Foo:
Code:
public class Foo
{
private String bar;
public String getBar()
{
return bar;
}
public void setBar( String bar )
{
this.bar = bar;
}
}
Then I have to do something like this:
Code:
// Suppose "foo" is some Foo object persisted before.
Foo newFoo = new Foo();
newFoo.setBar( new String( foo.getBar() ) );
session.save( newFoo );
while calling
Code:
newFoo.setBar( foo.getBar() )
would be incorrect because the bar reference would be shared by foo and newFoo?
Thank you folks!