-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to create this particular HQL equivalent using criteria?
PostPosted: Wed Feb 20, 2008 5:16 pm 
Newbie

Joined: Mon Nov 05, 2007 4:44 pm
Posts: 9
Mapping:
Class A1 {
String ID;
}
Class B1 {
String ID;
}

HQL:
SELECT {a.*}, {b.*}
FROM A1 AS a, B1 AS b
WHERE a.ID = b.ID

How can I create a HQL equivalent of the above query?

I tried
DetachedCriteria criteria = DetachedCriteria.forEntityName("A1", "a");
DetachedCriteria subCriteria = criteria.createAlias("B1", "b");
subCriteria.add(Restrictions.eq("a.ID", "b.ID"));

but it gave me
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: A1

Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 7:50 am 
Newbie

Joined: Wed Feb 20, 2008 8:53 am
Posts: 3
Try the following:


List items = session.createCriteria(A1.class)
.setFetchMode(“B1”,FetchMode.JOIN)
.list();


call the setFetchMode() of the Criteria class with two parameters: the name of the class with which the current class has to be joined and mode of the fetching of the data from the associated class. (Hibernate: Criteria Queries in Depth, by A.P.Rajshakhar) See the following website for an example:

http://www.devarticles.com/c/a/Java/Hibernate-Criteria-Queries-in-Depth/2/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 9:35 am 
Newbie

Joined: Mon Nov 05, 2007 4:44 pm
Posts: 9
Oh I forgot to mention that they don't have any foreign key relationship, so it looks like this.

Mapping:
Class A1 {
long ID;
String text;
}
Class B1 {
long ID;
String text;
}

HQL:
SELECT {a.*}, {b.*}
FROM A1 AS a, B1 AS b
WHERE a.text = b.text


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 2:16 am 
Newbie

Joined: Mon Nov 05, 2007 4:44 pm
Posts: 9
Anyone?


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