-->
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: Query <Joined-Subclass> attributes (starting on superc
PostPosted: Tue Mar 02, 2004 10:32 am 
Newbie

Joined: Tue Mar 02, 2004 8:35 am
Posts: 6
My question references the example query <from eg.Cat cat where cat.class = eg.DomesticCat>, chapter 10.7, Hibernate2 Reference Documentation.

1.) Additionally to the query example, I would like to query also the name from DomesticCat, e.g. <and name = 'ALEX'>. How would it look like in the example? If I write <and cat.name = ?> I get an exception like 'property unknown'.

2.) How do I query, if I work with <joined-sublass>. Is there a way to query attributes on joined subclases, see the example above. Currently I'm not able to do so.

Note:
As already mentioned in different postings "class" doesn't work with <joined-subclass>, it works only with <subclass>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 3:50 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about

query = from eg.DomesticCat cat where cat.name= ?
...

Cat myCat = (Cat)query.list().get(x);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 3:32 am 
Newbie

Joined: Tue Mar 02, 2004 8:35 am
Posts: 6
* Thanks for your response, but my real situation is following construct. Topic <one-ton-many> Action <joined-subclass> Request, Reminder, Adjudication.

* Now, I would like to get all Topics having Actions (abstract class) where
Request.status = 'PENDING' or Reminder.number = 'LAST'.

* My query is now ...
List lList = HibernateUtil.currentSession().find(
"select distinct stu from Topic as top " +
"join top.actions act " +
// NOW, IF HAVE ALL ACTIONS BUT I WOULD LIKE
// TO GO ON WITH SOMETHING LIKE THIS ...
"where Request.status = ? "
"and Reminder.number = ?",
new Object[] {new String("PENDING"),
new String("LAST")},
new Typ[] {Hibernate.STRING, Hibernate.STRING}
);

* But this doesn't work. Therefore my question again: How can I query attributes of subclass using <joined-subclass>? In my situation how I query "where Request.status = ? and Reminder.number = ?" ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:11 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
casting in HQL is not possible today.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 2:19 pm 
Newbie

Joined: Tue Mar 02, 2004 8:35 am
Posts: 6
emmanuel wrote:
casting in HQL is not possible today.


* Therefore the only way I can query on attributes of subclasses is to use nativ SQL queries see?

* To use one-to-one relations instead of joined sublasses or subclasses, what do you think about that approach?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 5:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
my opinion is that your domain model does not have to depend on query problem, so if you're sure this domain model is the best way to deal with your business, don't change it and use sql queries

Now if a one to one is also ok for your domain model, go for it as HQL is very powerfull


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.