-->
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.  [ 6 posts ] 
Author Message
 Post subject: cglib proxy doesn't intercept direct field access
PostPosted: Mon Mar 14, 2005 12:21 pm 
JBoss jBPM Developer
JBoss jBPM Developer

Joined: Thu Aug 28, 2003 11:56 am
Posts: 30
Location: Belgium
Hibernate version:
3.0 rc 1

Problem description:
direct field access is not intercepted by cglib proxy. (ignore this post if this is a known limitation)

first an object of CustomLongClass is given a name and stored in the database. after retrieval of this object in a new session, the debugger shows that the retrieved object is a cglib proxy and that the fields are not yet initialized. when accessing the name field directly (it's a public field!), it does *not* get initialized. creating a getter method and accessing the property via the getter solves the problem.

Mapping document:
Code:
<hibernate-mapping default-access="field">
  <class name="org.jbpm.context.exe.CustomLongClass">
    <id name="id"><generator class="native" /></id>
    <property name="name" />
  </class>
</hibernate-mapping>


Class:
Code:
public class CustomLongClass {
  long id = 0;
  public String name = null;
  public CustomLongClass() {
  }
}


regards, tom.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is pretty much a known limitation, afaik


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 4:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its not a limitation in my view.

you have only told hibernate that it should "monitor" the properties - not the field.

I would expect that if you used access="field" you would get the behavior you want (but i actually havent tried it ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 4:28 pm 
JBoss jBPM Developer
JBoss jBPM Developer

Joined: Thu Aug 28, 2003 11:56 am
Posts: 30
Location: Belgium
i had set the default-access="field" on the hibernate-mapping element.

i also tried to set the access="field" on the property after your comment to see if it made a difference, but no luck.

regards, tom.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 5:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmmm....afaik we can only intercept direct field access with the new lazy properties feature in hibernate3 - maybe that will solve your issue ?

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 5:49 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
You need to run "instrument" tool to intercept fields (it transforms bytecode in class files). Proxy is just a subclass generated at runtime and it can "intercept" methods only.
Probably "instrument" idea is not so bad if have good development tools.


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