-->
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.  [ 3 posts ] 
Author Message
 Post subject: access=field, dirty checking and proxies
PostPosted: Sun Feb 13, 2005 9:18 am 
Beginner
Beginner

Joined: Tue Feb 08, 2005 7:01 am
Posts: 21
Is automatic dirty checking of directly accessed fields supposed to work in Hibernate? Even when Hibernate uses a proxy?

Example pseudocode:
Code:
cat = session.load(id)
cat.name = "john"
tx.commit


This code doesn't update the cat record for me. While stepping through in a debugger it seems that Hibernate create a proxy for cat, the name field of the cat proxy is indeed set, but commit doesn't even check for a dirty object because it thinks the session is empty (PersistenceContext.hasNonReadOnlyEntities= true).

If I replace load() with get() in the above code (which does NOT instantiate a proxy), then it works as expected, it updates the record.

Hibernate version: 3.0beta4

Mapping documents: Class with access="field"


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 9:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You set an instance variable of the proxy. Not of the entity instance.

Don't use direct access to public instance variables in Hibernate (or OO in general).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 13, 2005 10:01 am 
Beginner
Beginner

Joined: Tue Feb 08, 2005 7:01 am
Posts: 21
thank you very much. It might worth to mention this in the doc or in the book. (I understand that it is reasonable to think that public fields is not OO enough, but if I am developing an application (not a library), trivial getters and setters has no benefit but only disadvantage: getCount() is less readable then count or even count(), more code, more members displayed in the IDE - and in the rare case when I indeed find later that I need some logic in the getter or the setter, it tooks only 10 seconds to refactor field access to getters setters using an IDE like Eclipse)


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