-->
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.  [ 2 posts ] 
Author Message
 Post subject: JPQL Query on Type
PostPosted: Wed Jul 11, 2007 5:33 pm 
Newbie

Joined: Thu Nov 09, 2006 9:42 pm
Posts: 13
Hello,

We recently ran into a situation where it would be nice to add a subclass of an entity to the model and query an entity based on what type an attribute is. The entities might look something like this:

Code:
@Entity class Root{
  @Id Long id;
  @ManyToOne Parent parent;
}
@Entity @Inheritance( strategy= SINGLE_TABLE) class Parent{
  @Id Long id;
}
@Entity class Child extends Parent{
  @Id Long id;
  @Basic String additionalAttribute;
}


Now I would like to select all Root instances where Root.parent is a Parent and not a Child. JPQL does not seem to support this, though a strongly typed object query language would seem to imply this is possible. If this were Java code it would be something like !(root.parent instanceof Child).

--
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 9:39 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
http://www.hibernate.org/hib_docs/entit ... yhql-where

Quote:
Likewise, the special property 'class' accesses the discriminator value of an instance in the case of polymorphic persistence. A Java class name embedded in the where clause will be translated to its discriminator value. Once again, this is specific to HQL.


Code:
select cat from Cat cat where cat.class = DomesticCat


Hope this helps!

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


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