thanks for answers.
Quote:
Why should calling Save set the properties in the child?
I can't set the property in the shild.
I'm not trying to import hibernate objects, but an xml file, so I can't set any property in the child.
When I import hibernate objects, I add children into the father and I set the father in the children. That's ok.
During the import of xml file, hibernate is looking for "pere" elements and, thanks to the mapping file, can import the father in db, then children. But it don't set the FATHER_ID in the Child
I never can access the data to update the FATHER_ID in the child, because the import doesn't use hibernate object, so I can't set the FATHER_ID property. That's my problem !!
I thought that hibernate do it automatically.
Look at my code:
Code:
Session dom4jSession = (Session) currentSession.getSession(EntityMode.DOM4J);
Transaction transaction = currentSession.beginTransaction();
// Read document with DOM4J
SAXReader saxReader = new SAXReader();
File file = new File(xmlFilePath);
org.dom4j.Document xmldb = saxReader.read(file);
// Get all "pere" elements to import
java.util.List l = xmldb.getRootElement().elements("pere");
Iterator it = l.iterator();
while(it.hasNext()){
Object next = it.next();
dom4jSession.save("chemin.pere", next);
}
transaction.commit();
currentSession.close();
Then the Hibernate trace :
// get sequences in db for the father en the child
Hibernate: select SEQ_PERE_ID.nextval from dual
Hibernate: select SEQ_ENFANT_ID.nextval from dual
// Insertin the db: during fluch(in the save method) first the father, then the child
Hibernate: insert into PERE (champ1,champ2,...) values (?, ?, ...)
Hibernate: insert into ENFANT (champ1,champ2,...) values (?, ?, ...)
but for the child : ---> MyProject.FK_TEMPLATE) violated - parent key not found