Hello
I have been trying to figure this out for a while
I have 2 objects
here are relevant snippets
Party implements Externalizable
private List phones = null;
/**
* @hibernate.bag name="phones" cascade="all-delete-orphan"
*
*@hibernate.collection-key column="id"
* @hibernate.collection-one-to-many class="org.marcus.Phone"
*/
public java.util.List getPhones() {
return phones;
}
public void setPhones(java.util.List phones) {
this.phones = phones;
}
Phone implements Externalizable
private Party party;
/**
* @hibernate.many-to-one column="id" cascade="none"
*
*/
public org.marcus.Party getParty() {
return party;
}
Everything works fine if the objects are not sent to another tier through rmi
I can do this
Phone phone = new Phone();
party.getPhones.add(phone);
try{
Session session = HibernateUtil.currentSession();
Transaction tx= session.beginTransaction();
session.saveOrUpdate(party);
// System.out.println("Saving or updating " + entity);
session.flush();
tx.commit();
HibernateUtil.closeSession();
}catch(Exception ee){
System.out.println(ee);
}
everything works fine
if I go through rmi (assume the the objects are sent out through rmi and then fiddled with and returned to the server)
the first time I tru to save party I get this error
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: org.marcus.Name.party
the second time I get this error
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: org.marcus.Name.party
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 1069, of class: org.marcus.Party
The errors occur regardless of whether I alter the objects or not.
I have also tried this right before trying to save party thinking maybe hibernate got confused and assumed party and phone.getParty referred to different things
if(entity instanceof Party){
System.out.println("doing party");
Party party = (Party)entity;
Party newparty = (Party)getEntity(entity, null);
Iterator i = party.getPhones().iterator();
while(i.hasNext()){
Phone phone = (Phone)i.next();
phone.setParty(newparty);
}
}
getEntity is basically a function that retrieves stuff from the database
Marcus
|