-->
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: Headache Problem on reading subclass objects in HQL
PostPosted: Tue Jun 13, 2006 3:11 am 
Beginner
Beginner

Joined: Mon May 22, 2006 12:12 am
Posts: 23
Hi All,

LegalPerson has 2 subclasses: Person & Organization. I've problem retrieving the objects. Linking to LegalPersonAlias with one-to-many relationship.

Similar structure of the following code didn't have problem if the class, LegalPerson, have no subclasses. But now it has the 2 sub-classes and have the problem appeared;

my HQL is like this "from LegalPerson lp, LegalPersonAlias lpa where lpa.origLegalPerson = lp";

On running the code below, it hits error as soon as (even before my if-checkings) running the line: " Object[] objs = (Object[])ie.Current;"

The error is:
"Unable to cast object of type 'RHU.RAIS.Business.Person' to type 'System.Object[]'."



How should I cast the objects to its respective (sub-)class?


portion of the code:
...
for (IEnumerator ie = q.List().GetEnumerator(); ie.MoveNext(); )
{

Object[] objs = (Object[])ie.Current;
LegalPerson lp = (LegalPerson)objs[0];

if (objs[0] is Person)
{
lp = objs[0] as Person;
}
else
{
if (objs[0] is Organization)
{
lp = objs[0] as Organization;
}
else
{
if (objs[0] is LegalPerson)
{
lp = objs[0] as LegalPerson;
}
}
}

...........

Thanks!


Top
 Profile  
 
 Post subject: Re: Headache Problem on reading subclass objects in HQL
PostPosted: Tue Jun 13, 2006 3:14 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
fly2moon2 wrote:
Hi All,

" Object[] objs = (Object[])ie.Current;"

The error is:
"Unable to cast object of type 'RHU.RAIS.Business.Person' to type 'System.Object[]'."



How should I cast the objects to its respective (sub-)class?


portion of the code:
...
for (IEnumerator ie = q.List().GetEnumerator(); ie.MoveNext(); )
{

Object[] objs = (Object[])ie.Current;
LegalPerson lp = (LegalPerson)objs[0];



Why do You think that the ie.Current should be array/list instead of single value?
Try to replace

Object[] objs = (Object[])ie.Current;
LegalPerson lp = (LegalPerson)objs[0];
with
LegalPerson lp = (LegalPerson)ie.Current;

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 3:21 am 
Beginner
Beginner

Joined: Mon May 22, 2006 12:12 am
Posts: 23
Thanks Gert,


However, my HQL is like this "from LegalPerson lp, LegalPersonAlias lpa where lpa.origLegalPerson = lp";

So, beides the LegalPerson object, I have the LegalPersonAlias object.

Then how can I get corresponding values from ie.Current?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 3:27 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
fly2moon2 wrote:
Thanks Gert,


However, my HQL is like this "from LegalPerson lp, LegalPersonAlias lpa where lpa.origLegalPerson = lp";

So, beides the LegalPerson object, I have the LegalPersonAlias object.

Then how can I get corresponding values from ie.Current?


Sorry, I overlooked that HQL somhow. And I do not know the answer :(

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: it works!
PostPosted: Tue Jun 13, 2006 8:15 am 
Beginner
Beginner

Joined: Mon May 22, 2006 12:12 am
Posts: 23
Hi,

Apologize to all. As I don't see the problem now after much efforts to find out what went wrong.

Final answer is : nothing wrong. My original code works! Something wrong with my PC. Only find that the program runs with no error after rebooting few times.

Sorry.


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.