-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Object not updated in database
PostPosted: Fri Sep 05, 2008 7:50 am 
Newbie

Joined: Fri Jun 13, 2008 4:52 pm
Posts: 9
Location: Västerås, Sweden
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.