Hello,
I am working on an Graphical Editor based on GEF. The Model is saved in a database using hibernate.
All of my model-objects are fetched eager.
I have 2 EntityManagers, one to read model data and the second to write changes back to database via merge
First reading example:
Code:
static public Diagram findByProjectAndName(String pProjectName, String pName) {
Diagram lResult = null;
sReadingManager.clear();
sReadingManager.getTransaction().begin();
List<Diagram> lDiagrams = sReadingManager.createQuery(
"from Diagram d where d.project.name = '" + pProjectName + "' " +
"and d.name = '" + pName + "'")
.getResultList();
if (lDiagrams.size() == 1) {
lResult = lDiagrams.get(0);
}
sReadingManager.getTransaction().commit();
return lResult;
}
Second, write data back to db:
Code:
static public void mergeDiagram(Diagram pDiagram) {
sWritingManager.getTransaction().begin();
Diagram lDia = sWritingManager.merge(pDiagram);
sWritingManager.getTransaction().commit();
}
Everything works fine so far. I get the diagram, do some changes to its model and then clall merge after saving.
But there is still one Problem left, if I delete an element of the diagram, hibernate will not delete it in the database. Hibernate will only set the references on the deleted element to null:
DEBUG SQL:393 - update DiagramElement set name=?, viewInfo=?, diagram_fk=? where DIAGRAMELEMENT_ID=?
DEBUG SQL:393 - update DiagramElement set diagram=null where diagram=?
Do I have to delete the element explicit in a query or am I doing something wrong?
I would appreciate any help!
Thanks in advance & best regards.