Hi,
Is it possible to make transient instances persistent whenever they are associated with persistent objects? In other words, if I had
Code:
Person parent = new Person();
session.save(parent);
Person child = new Person(); // child is transient
parent.addChild(child); // child becomes persistent
outside of modifying the mutator semantics and putting in Hibernate code there. If so, how is this done? Ideally, I would like the object to become persistent first before the mutator method gets called because of how I've implemented hashCode() (includes the generated identifier).
Does Hibernate wrap mutator methods?
In case I do have to change the mutator methods, is there a function that indicates whether a given object is transient or persistent? (or if it has even been defined as a Hibernate persistent class?) A'la
Code:
void addChild(Person child) {
if (session.isTransient(child)) {
session.persist(child);
}
this.child = child;
}