-->
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.  [ 2 posts ] 
Author Message
 Post subject: Association guidelines
PostPosted: Wed Jul 20, 2005 9:58 am 
Beginner
Beginner

Joined: Thu Jan 13, 2005 10:31 am
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.17

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

It is a general question: what are the general guidelines to decide if an association should be a uni or bi?

For example I have an Employee table which has location_id as a column which refers as a foreign key to location_id in Location table. So
public class Employee implements java.io.Serializable {
private int employeeId;
private Location location;
...
}

If I define Location class why should I include a reference to Employee?
private Set employees;


Top
 Profile  
 
 Post subject: Association guidelines
PostPosted: Wed Jul 20, 2005 11:25 am 
Beginner
Beginner

Joined: Mon Apr 12, 2004 6:33 pm
Posts: 35
It depends on the usecase(s) and on the way you want to travel the object graph. If you want to obtain a set of employees associated with a specific location you can fire an hql query on Employee with location as an argument.
If you make the association bidirectional you can do
Code:
location.getEmployees()
.


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