Hi everyone,
I have an entity called "Document" which has a many-to-one relation to the entity "Client". But on the Client side the relation to Document is one-to-one since I only want to save a reference to the latest Document.
My problem now is this: First I want to create and persist a new Document including a reference to a Client, which works.
But then I want to set the "Document" reference in Client to point to the new Document. This works when I step through the java code but when I check the contents of the database later I find that the Client record in question still points to an old Document and not the new one.
I'm getting no errors. It just seems like that Client instance is not synchronized with the db. What can be the reason for this?
I can add that I'm closing the Session through a filter and when I stepped through the code I saw that this happens after the relevant code has been executed (at least it looks that way).
Maybe the problem is due to my Hibernate mapping files since I'm not absolutely sure I've written them correctly. Therefore I'm pasting the most relevant parts of them here:
Code:
<hibernate-mapping>
<class name = "BusinessLogic.Entities.Document" table="document">
.....
<many-to-one name = "client" column = "clientId" foreign-key= "clientId" class = "BusinessLogic.Entities.Client" cascade = "save-update" fetch = "join"/>
.....
</hibernate-mapping>
<hibernate-mapping>
<class name= "BusinessLogic.Entities.Client" table = "client">
.....
<one-to-one name = "docRef" foreign-key = "docRef" class = "BusinessLogic.Entities.Document" cascade = "delete"/>
....
</hibernate-mapping>
I really hope somebody can help me with this. That would be great!
Thanks in advance!
/Ylva