-->
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.  [ 5 posts ] 
Author Message
 Post subject: Suggestion for automating proxy casting
PostPosted: Thu May 04, 2006 4:12 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
Hi,

Why doesn't Hibernate automate proxy casting to avoid having to do this manually as described here? http://www.hibernate.org/hib_docs/v3/re ... ng-proxies

You can quite easily scan the bytecode for a casting operation and replace it with a Hibernate-safe call. For example:

Given:

(TargetType) myObject

replace it with:

(TargetType) Hibernate.getProxiedObject(myObject)

then define Hibernate.getProxiedObject() as:

Code:
if (object instanceof HibernateProxy)
{
  HibernateProxy proxy = (HibernateProxy) object;
  LazyInitializer initializer = proxy.getHibernateLazyInitializer();
  return initializer.getImplementation();
}
else
  return object;


Is there any reason we aren't already doing this? The benefit would be that you wouldn't need to introduce any Hibernate-specific calls in the code.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 3:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we dont rely on build time instrumention of *all* your classes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 3:24 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
I am primarily concerned with casting that occurs within the objects that Hibernate persists. If Hibernate were to fix the casting within those classes, it would be a huge step forward.

Also, I believe in the above case you could do the bytecode manipulation at runtime (as opposed to build time), the same time you are building the proxy classes. What do you think?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 3:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no we can't as we do cannot guarantee control over the classloader

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 1:58 pm 
Beginner
Beginner

Joined: Thu Aug 28, 2003 3:09 pm
Posts: 39
Location: Brazil
Hi,

would it be possible to have another ant task which do that?
Just like there is the instrument task which do lazy loading, I think Hibernate could add another one. This would allow people which want this behavior to do it at compile time.

Or better (at least from my point of view), Hibernate could have an option to use lazy loading with bytecode instrumentation and return plain objects instead of proxies.

At my company usage, when we access a proxy, in 99% of time, we want to access other fields of proxy, so, we end up loading the object anyway. So, if we could use hibernate to just objects under demand (which is possible currentlywithout proxies and with bytecode instrumentation) and return plain objects and not proxies (which I don't know how to do it now) would be very good!

Thanks in advance.


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