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.  [ 10 posts ] 
Author Message
 Post subject: INNER JOIN
PostPosted: Mon Nov 14, 2005 7:20 am 
Newbie

Joined: Mon Nov 14, 2005 6:55 am
Posts: 5
I have such sql:

SELECT * FROM Alpha INNER JOIN (SELECT MAX(created) AS pcreated FROM Alpha GROUP BY id) ids ON created = ids.pcreated WHERE id = '100' ORDER BY created DESC

How could I pass this to session in order to retrive data from db?

ERROR: , expected in SELECT

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 8:10 am 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
session.createSQLQuery(...);

see: http://www.hibernate.org/hib_docs/v3/reference/en/html/querysql.html#querysql-creating

By(te)!!!

-

Please don't forget to credit ,-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 10:10 am 
Newbie

Joined: Mon Nov 14, 2005 6:55 am
Posts: 5
Thank ypu for reply.

But could you please give me a link to Hibernate 2.0 (that I'm currently use) API to resolve this problem. In 2.0 release there is no createSQLQuery method in Session.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 10:25 am 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
[url]http://www.hibernate.org/hib_docs/api/net/sf/hibernate/Session.html#createSQLQuery(java.lang.String,%20java.lang.String[],%20java.lang.Class[])[/url]

Is this what do you want?

Hi

-

Please don't forget to credit ,-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 10:48 am 
Newbie

Joined: Mon Nov 14, 2005 6:55 am
Posts: 5
Thanks again.

I've noticed that Session.createSQLQuery is available since 2.1 version...
So, is there any workaround to do it WITHOUT createSQLQuery method? :)

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 10:58 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
session.getConnection()

Then use the usual JDBC way of passing a query and getting a resultset.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 11:05 am 
Newbie

Joined: Mon Nov 14, 2005 6:55 am
Posts: 5
Well, but I need to retrieve list of object entities...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 11:12 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Is there any reason why you can't use HQL?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 11:19 am 
Newbie

Joined: Mon Nov 14, 2005 6:55 am
Posts: 5
Yes :)

When I try to do createQuery with:

SELECT * FROM Alpha INNER JOIN (SELECT MAX(created) AS pcreated FROM Alpha GROUP BY id) ids ON created = ids.pcreated WHERE id = '100' ORDER BY created DESC

I have exception: , expected in SELECT


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 11:24 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Ah ha.

The * threw me as it's not valid HQL afaik. You're querying objects not values. Without mapping I couldn't hazard a gues at how to write a valid HQL query for what you want.


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