Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate 3.0 handler.target

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Class A
Class B inherits class A
I have hibernate object x. If you do

you get true

If you do



you get false

BUT

When I look in intellij and go into the object x I see that x.handler.target is actually B and that is what I expect.


SO 2 questions:
1. what is this handler and target?
2. How to I get it so in runtime I can find out what type is object x?

Much obliged!
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Hibernate objects that are lazily initialized are managed by javaassist (or cglib for older versions) proxy objects. Basically what happens is the proxy is generated by sub-classing your object. When a lazy initialized object becomes initialized the handler.target updates to reflect the initialized properties.

2. The reason you are having problems is because instance of does not work on the proxy object. This is a problem you will have with lazy loaded objects that are part of a type hierarchy. You have a couple options:

2a. Eagerly fetch the object
2b. Try de-proxying the object



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic