-->
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.  [ 9 posts ] 
Author Message
 Post subject: Dirty check
PostPosted: Fri May 18, 2007 2:14 pm 
Beginner
Beginner

Joined: Sat Apr 07, 2007 4:42 pm
Posts: 24
Hi,

how determines hibernate that an entity is dirty?
hashCode? equals? Comparing field values oder getter returns?

Thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 3:26 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
There's a snapshot copy in Session to compare against.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 4:33 pm 
Beginner
Beginner

Joined: Sat Apr 07, 2007 4:42 pm
Posts: 24
Yes, but how is it compared? Field by field, getter by getter, equals, hashcode..?

My problem is that my entity gets not updated although I changed a field value like this:

@Transient private String a;
private String b;

void setA(String a) {
this.a = a;
this.b = computeB(a);
}

Thus it seems that if b is not changed by setter setB(), dirty is not true.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 2:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
where is your @Id annotation placed?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 20, 2007 5:15 am 
Beginner
Beginner

Joined: Sat Apr 07, 2007 4:42 pm
Posts: 24
In the same class:

Code:
@Id
@GeneratedValue(strategy=GenerationType.AUTO) @SuppressWarnings(value={"unused"})
private int id;


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 9:26 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Properties are accessed however you specify they should be accessed. In JPA, the position of @Id determines this. If you put that annotation on a field, then field-access is used. If it's on a getter, property access is used.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 9:38 am 
Beginner
Beginner

Joined: Sat Apr 07, 2007 4:42 pm
Posts: 24
Thanx.

But this keeps my question still open:

Why does hibernate not check that my entity is dirty and how is this check done in general?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 10:52 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Follow the directions when posting and you'll get much better help.

http://www.hibernate.org/ForumMailingli ... AskForHelp

Quote:
When posting

* Give as much information as possible. Don't ignore the bullet points in the text field, fill out the required information. Yes, everything is needed in almost all cases.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 21, 2007 11:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
is your entity actually associated with a persistence context ?

with respect to dirtychecking then the general explanation is above...it takes a snapshot and then do a comparison when needed.

details can be seen in the code...look for Type.isEquals(x,y) method and friends.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.