-->
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: Type Hierarchies: Queries in JPQL vs. Criteria API
PostPosted: Sat Apr 23, 2011 3:47 am 
Newbie

Joined: Fri Apr 22, 2011 5:27 am
Posts: 2
Hi all,

in my projects data model some Type Hierarchies are mapped using a Descriminator Column on an abstract base Type. Sometimes Types have references to abstract base Types but I have to do queries on specialized Attributes. Currently I´m using Sub-Queries e.g.
Code:
@Entity
@DiscriminatorColumn(length = 2)
class Base{
  String value;
  ...
}

@Entity
@DiscriminatorValue("A")
class A extends Base{
  ...
}

@Entity
@DiscriminatorValue("B")
class B extends Base{
  String anotherValue;
  ...
}

@Entity
class X {
  private Base base;
  ...
}

class SomeService{
  void service(){
    /*
   find all X where X#base instanceof B and ((B) base)#anotherValue = "Hello World!";
    */
   
    Select x from X x where x.base in (Select b from B b and a.anotherValue="Hello World!")
  }
}


I don´t like this sub-query (last but not least because of potential performance risks). My questions are: Is there another way to express that with JPQL? Is there a way to build this query using the Criteria API?

Thanks all.


Top
 Profile  
 
 Post subject: Re: Type Hierarchies: Queries in JPQL vs. Criteria API
PostPosted: Tue Apr 26, 2011 3:13 am 
Newbie

Joined: Fri Apr 22, 2011 5:27 am
Posts: 2
When using JPQL this could be done using:
Code:
TypedQuery<A> query = em.createQuery(
"select a from A a where dtype='A'", A.class);


So, JPQL makes use of the "dtype" column. I did not find a way to execute something similar with Criteria API. Any ideas?

Thanx again


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.