-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to mark data 'dirty' without calling 'setter' method
PostPosted: Fri Jun 09, 2006 7:25 pm 
Newbie

Joined: Fri May 26, 2006 10:55 am
Posts: 4
I have a class which holds raw byte[] data, which will occasionally be updated for version changes. The modification can be made automaitically in the 'setData' method, when the object is first loaded from the database, but how can I be sure it will be saved back? Will Hibernate call the 'getData' method and compare, or is there an easy way to set the 'data' field as dirty, so that that data is saved when the transaction ends?

Hibernate version: 3.1.3

Mapping document:
Code:
  <class name="Raw" table="raw">
    <id name="id">
      <generator class="native"/>
    </id>
    <property name="data" not-null="true"/>
  </class>


Pojo class:
Code:
public class Raw {
  int id;
  byte[] data;
  public void setData(byte[] data) {
    this.data = data;
    updateDataIfOld();
  }
  public byte[] getData() {
    return data;
  }
  ...
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 1:05 pm 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
I think what you may want is:

Code:
<class name="Raw" table="raw" optimistic-lock="dirty">
    <id name="id">
      <generator class="native"/>
    </id>
    <property name="data" not-null="true"/>
  </class>


This should check the fields for any changes on flush. If I recall, this can slow things down a bit if you're updating these objects frequently.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


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

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.