-->
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.  [ 3 posts ] 
Author Message
 Post subject: Nested criterias and entity type
PostPosted: Fri Jun 19, 2009 8:19 am 
Newbie

Joined: Fri Jun 19, 2009 7:56 am
Posts: 3
My model has two class hierarchies:
A2 extends A1
A3 extends A2
and
B2 extends B1
B3 extends B2

There is a relation from A1 to B1 named "b",
Set<B1> b;
in A1

I would like to do queries involving both sub classes of A1 and B1.

When doing queries using the org.hibernate.criterion package, I can do

Criteria c = DetachedCriteria.forEntityName(A1.class)
to create a root criteria, and then join with the other class using
c.createCriteria("b")
to create a nested criteria. This is all very good.

When creating the initial criteria,
DetachedCriteria.forEntityName(A1.class)
gives my all instances of sub classes of A1 (including A1).
DetachedCriteria.forEntityName(A2.class)
would give my all A2's and A3's, but not A1's.
This is also very good.

So to my question.
How do I specify the same for the B's, a restriction on the B1 class hierarchy?
The
Criteria.createCriteria(String associationPath)
do not take any entity type arguments. What I would like is
Criteria.createCriteria(String associationPath, Class entityType)

Say that I would like to have
all A2-s (including A3-s) and the related B2-s (including B3-s)

How do I do this using the org.hibernate.criterion package?
I know that hibernate uses a database column named dtype to discriminate subclasses in the same table,
and I could use this for add some kind of an sql criterion with information about the B1-B2-B3 classes.
But this gets really ugly, as then I will have to use a hard-coded representation of the class hierarchies
in the code, and I would also depend on hibernate not changing the name of the dtype column.

Can someone please help me. This should be basic functionality in a OR-mapping tool.


Regards
Øyvind Jergan


Top
 Profile  
 
 Post subject: Re: Nested criterias and entity type
PostPosted: Fri Jun 19, 2009 12:26 pm 
Newbie

Joined: Thu Jun 18, 2009 2:53 pm
Posts: 1
So to my question.
How do I specify the same for the B's, a restriction on the B1 class hierarchy?
The
Criteria.createCriteria(String associationPath)
do not take any entity type arguments. What I would like is
Criteria.createCriteria(String associationPath, Class entityType)


In your example you should be able to create a Criteria for A then:

criteria.createCriteria(associationPath).add(Criterion) where Criterion is an Example of you B and your association path would be the field name of B in A.

Thanks


Top
 Profile  
 
 Post subject: Re: Nested criterias and entity type
PostPosted: Mon Jun 22, 2009 5:18 am 
Newbie

Joined: Fri Jun 19, 2009 7:56 am
Posts: 3
Chsquill wrote:
So to my question.
How do I specify the same for the B's, a restriction on the B1 class hierarchy?
The
Criteria.createCriteria(String associationPath)
do not take any entity type arguments. What I would like is
Criteria.createCriteria(String associationPath, Class entityType)


In your example you should be able to create a Criteria for A then:

criteria.createCriteria(associationPath).add(Criterion) where Criterion is an Example of you B and your association path would be the field name of B in A.

Thanks


Yes, that sounds correct.
So my question is then really, how do I create a Criterion that matches
"All instances of class B2 (and its sub classes including B2), but no instances of B which is not sub class of B2 (for example B1)"
?

Øyvind


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