-->
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: Newbie question
PostPosted: Wed Feb 15, 2006 3:42 pm 
Newbie

Joined: Wed Feb 08, 2006 6:17 am
Posts: 9
Dear All,
I am new to Hibernate and I'm currently writing an application using version 3.x. I have an existing databse to work against and so I'm modelling my POJOs against these tables.

What I need to do is run an HQL query to return a Role object. This role object in turn contains a number of Participation objects which I want returning in a collection object (I've written the code for that in my Role object). What I can't get is how to map the Role and Participation objects in the configuration file. Am I along the right lines of using the <set> tag?
The SQL that I'm trying to emulate is this:

select * from Role , Participation where Role.ID = Participation.RoleID

Thanks in advance

Angus


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 5:29 pm 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Exactly right.
You should really consider reading the relevant section of the (easy to read) manual since it is the FIRST question everyone asks when using Hibernate - not a dig, but really, it would save you time!

You are correct though.

Code:
Role {
  Long id;
  Set <Participant> participents; // not that you need Set and NOT HashSet (as H8 replaces them at runtime)

  // getters & setters
}

Participent {
  Long id;
  Role role;
}


Then a Set is a good way to model this in the mappings.

If you model it as a lazy association, your hql would be
Code:
from Role join Participants

Once you've done this, if it doesn't work, post your mappings, java files and error stack trace and people will offer very detailed help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 5:29 pm 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Exactly right.
You should really consider reading the relevant section of the (easy to read) manual since it is the FIRST question everyone asks when using Hibernate - not a dig, but really, it would save you time!

You are correct though.

Code:
Role {
  Long id;
  Set <Participant> participents; // not that you need Set and NOT HashSet (as H8 replaces them at runtime)

  // getters & setters
}

Participent {
  Long id;
  Role role;
}


Then a Set is a good way to model this in the mappings.

If you model it as a lazy association, your hql would be
Code:
from Role fetch participants

Once you've done this, if it doesn't work, post your mappings, java files and error stack trace and people will offer very detailed help.


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.