-->
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: Hibernate.initialize + JTA + Polymorphism + Casting
PostPosted: Wed Dec 14, 2005 6:49 pm 
Good day !

I've been using Hibernate for a while (2 years) and never tried developing using Hibernate and Lazy.
Ok, i'm using version 3.0.5 and i'm also experiencing some weird behaviours.
I'm under a JTA transaction on JBOSS 4.0.2.
I have an Object that belongs to a class called AutomaticActivity.
Class AutomaticActivity extends Activity.
This is the situation:

Hibernate.getClass(nextActivity)
.getSimpleName()
.equals("AutomaticActivity")) returns TRUE.

the Object nextActivity, if you look in the debugger shows:

Activity$$EnhancerByCGLIB$$blablabla
the toString() shows blabla.AutomaticActivity@3423e23

Everything fine so far. I proved that i have a AutomaticActivity used as Activity and proxied by CGLIB.

The question is: HOW DO I CAST THIS damn Object to my dear AutomaticActivity to get hold of specific fields?

I tried to initialize the proxy by Hibernate.initialize but it doesn't do anything.
I tried a straight cast even knowing it wouldn't work.
Is there a way to get a value from a specific field in the subclass using the proxied Object?

I'm sure i'm missing something in here.
I really appreciate any help
Thanks in advance,

:LuizDecaro.

PS: A workaround I found for this (ugly one) is to load an AutomaticActivity by the Id from my proxied Object from the DB.


Top
  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 6:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate reference documentation, chapter "Performance". Read about proxies and how to cast them.


Top
 Profile  
 
 Post subject: Not exactly
PostPosted: Wed Dec 14, 2005 7:33 pm 
I don't want to be rude mate but
If you had read my post clearly including the ps you'd had noticed that i'm not stupid. (cos' you made me feel like)
And you could have answered my other questions too.
--------------------------------------------------------------
Two years ago helping used to be better around here.
--------------------------------------------------------------


Top
  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 8:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't care how you feel. The fact is that your question is answered in the documentation. I gave you enough information to press CTRL-F and search for it. I realize that this is probably too much to ask for.
[/i]


Top
 Profile  
 
 Post subject: Ok then
PostPosted: Wed Dec 14, 2005 8:12 pm 
Y're right mate i know that reference guide by heart since v1.0 and you're talking about chapter 19.
What I really wanted to know is that if there is another (more elegant) way embedded in the framework to cast without having to question to the superClass isBLABLA() and loadById(.class, Serializable)

Or if there is a way to get straight info from a field in the subclass from a method using the proxy.

It seems you lost another chance to help.

CHEERS MATE!!


Top
  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 8:31 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, there is a much nicer way, but we are all trying to hide it from you and don't document it.... Sheesh. And I will now gladly pass on this chance to help you to somebody else.


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.