-->
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.  [ 7 posts ] 
Author Message
 Post subject: many-to-one association
PostPosted: Wed Jan 07, 2004 8:34 am 
Newbie

Joined: Wed Jan 07, 2004 8:10 am
Posts: 8
Hi there,

I am a newbie to hibernate and was wondering if anyone could help..

I have a SQL statement that goes across a number of views

SELECT ci.CONDITIONITEMID, c.description, ci.DESCRIPTION
FROM REFCONDITIONITEM ci, refcondition c, tradeconditionitem tc
WHERE tc.tradeid = ?
and ci.conditionid = c.conditionid
and ci.conditionitemid = tc.conditionitemid
order by c.entryOrder, ci.entryorder

The result from the query is then used to populate a java Arraylist object and the object is returned.

I need to be able to map all the different columns form the different views to one data access object, say ConditionsDAO.java so that when the user gets hold of this object they have the results of the above query...a bit like the arraylist that it currently generates.

Is this possible to use many-to-one tag to do this? how do you use it to do what I want to do?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If this is really a one-to-many, you can map it as a class A having a Set attribute containing Bs. You can however of course write an HQL query which returns you a array list containing duplicates of your A or an attribute of A if that is what you desire. Hibernate maps Object models, so if you can represent this as a proper OO model, we might be able to tell you how to map it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:43 am 
Newbie

Joined: Wed Jan 07, 2004 8:10 am
Posts: 8
I want to be able to return the results of this query as a Java object using hibernate. Does HQL allow you to do something like this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 8:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Yes, it does. If you can't map it properly, use select new, like in:

Code:
select new Family(mother, mate, offspr)

See the Docs: http://www.hibernate.org/hib_docs/reference/html/query-language.html#query-language-s4


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 9:06 am 
Newbie

Joined: Wed Jan 07, 2004 8:10 am
Posts: 8
I am not quite sure if I knwo what needs to be done here!!

For instance, where does the HQL statement sit?

What If I want it to return an object called ConditionsDAO? what should the getters and setter for this class do?

I can not quite put the whole picture together!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please learn how to use Hibernate first, check out the documentation or probably some tutorials frome here: http://www.hibernate.org/78.html.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 9:19 am 
Newbie

Joined: Wed Jan 07, 2004 8:10 am
Posts: 8
good idea!


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