-->
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: Example simple join query
PostPosted: Thu Apr 01, 2004 10:16 am 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
just having a bit of trouble with hsql syntax. I've read the other posts and I guess I'm stupid cos I still dont get it.

Ideally i can use a prepared statement using session.find the problem is I've a joing table thats not a java object.

I want to do this in a find method or query if i must

select distinct c.* from category as c, category_season cs where c.id = ? and cs.id = ?


the problem is there's not java class modeling category_season so i've been trying

list = session.find("from com.foo.Category as c , category_season as cs where c.id = ? and cs = ?",new Object[] {catId,seasonId},Type[] {..});

of course to no avail.

I read the post linked on the FAQ's .. do i have to use createSQLQuery and do all that jazz with the braces or is there a way using find.

Cheers Mark


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 6:14 pm 
Beginner
Beginner

Joined: Wed Nov 26, 2003 9:04 am
Posts: 23
I'm sure there must be something I'm missing although it could be the black team as moved from sql docs to java api's.

I've gone through the docs and I'm very happy that cats have kittens and such like but how do i do a select statement like the one i described when one of the tables isn't a java object?

This must come up all the time wit many-to-many relationships so please someone show me how stupid i am , and/or point to me to some concise documention that i've been too stupid to notice.

Cheers Mark


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 02, 2004 1:22 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if category_season is an association table, you should have mapped Category, Season and a many-to-many between them,
so
Code:
from Category c inner join c.seasons s where c.id=? and  s.id=?

does the job.
If categorySeason has property (property inside the association link), then you should map it.

_________________
Emmanuel


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.