-->
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.  [ 9 posts ] 
Author Message
 Post subject: Type casts in the HQL
PostPosted: Tue Feb 24, 2004 6:26 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Hi there!

I would like to ask if it is possible to use type casts in the Hibernate Query Language.

I mean the following query:
Code:
"from SomeClass obj where ((Child)  (obj.parent)).someChildProperty=123"


where Child is subclass of Parent and SomeClass has reference to Child via member of Parent class:

Code:
public class Child extends Parent {
    int childProperty;
}

public class SomeClass {
    Parent parent;
}
...
SomeClass obj = new SomeClass();
obj.parent = new Child();


Thanks,
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 12:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is not possible at this time. Instead, use:

select child.parents from Child child where child.someProperty=123


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 2:14 pm 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Pardon, but I did not get it.

Child is a subclass of Parent. I think I wrote not to good examle, it does not relate to "9. Parent/Child Relationships". Child class does not have any HAS-A assosiations with Parent, only IS-A relationship (Child IS-A Parent, but has not any references to Parent).

Gavin, is your example valid?
Code:
select child.parents from Child child where child.someProperty=123


Thanks,
Leonid Shlyapnikov


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 2:59 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
If that's the case... you should be mapping this as a <subclass> or <joined-subclass>. Are you doing that? Then you will be able to query for it correctly and hibernate with cast it correctly for you. Which means you could get all the Parents and do an "instance of" to see if the object is an instance of your child or not. You could also just get all the children. So your mappings and I'll try to help you. Or someone from the team will help you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2004 3:00 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
and check this out in the docs... http://www.hibernate.org/hib_docs/reference/html/inheritance.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 25, 2004 4:27 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Hi tcollins,

I mapped the inheritance properly. The question was if is it possible to use class casts in Hibernate Query Language. Gavin said that at this time is not possible and wrote some HQL example that I don't understand.

Now I have the aswer and junit test that said Gavin is right (no class casts in HQL:)

I found workaround for my query, question is closed.

Thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:00 pm 
Newbie

Joined: Mon Nov 22, 2004 12:53 pm
Posts: 2
Is there something new about this topic? Is there a posibility to have dynamic cast in HQL? Something like "from Credetial as c where ((Badge) c).cardNumber=1234". Here Badge is a joined-subclass of Credential. Please let me know. Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, no such thing is implemented yet


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 22, 2004 1:04 pm 
Newbie

Joined: Mon Nov 22, 2004 12:53 pm
Posts: 2
Could you tell me if you planned this to implement and when I should expect it?
Thank again!


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