-->
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: Setter for embedded value - lost update
PostPosted: Fri Apr 04, 2008 8:15 am 
Newbie

Joined: Fri Apr 04, 2008 7:27 am
Posts: 1
Hello,

I wrote a POJO (named "Codes") which uses a wrapper objects for Strings ("TextWrapper").
Code:
public class Codes {
    private TextWrapper value;
    //other values   

    //setter, getter for all properties
    //equals, hashCode
}
and
Code:
public class TextWrapper {
    private String text;
    setText(), getText(), equals(), hashCode()
}




My problem is the setter-method for the value property. When I define the setValue(String newValue) like

Code:
setValue(String newValue) {
    this.value = new TextWrapper(newValue);
}
everything works fine.



But when I try to prevent the instantiation of new TextWrapper objects with the code

Code:
setValue(String newValue) {
    if (this.value == null)
        this.value = new TextWrapper(newValue);
    else
        this.value.setText(newValue);
}
the update will be lost when I call a flush or commit.

All involved classes have implemented equals and hash methods. What else can I do to tell hibernate that the value is dirty and the database needs an update?


Thanks in advance,
Björn

Hibernate version:
3.2.3ga

Code between sessionFactory.openSession() and session.close():
Code:
Codes c = codesDAO.read(id);
c.setValue("something new");
commit();



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.