Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Using OneToMany or ManyToOne . A Performance issue
Using OneToMany or ManyToOne . A Performance issue [message #646419] Thu, 23 December 2010 21:48 Go to next message
Arun Joy is currently offline Arun Joy
Messages: 10
Registered: July 2010
Junior Member
I have a company entity and an employee entity

I can model it as

//Approach 1
class company
{
String id;
@OneToMany
List<Employee> employees;
}

OR as

//Approach 2
class employee
{
String id;
@ManyToOne
Company company;
}


If i am not interested in a bidirectional relationship between the entities,

Approach 1 would produce 3 Database table like this

Table : Company

Id

Table : Employee

Id

Table : Company_Employee

CompanyId EmployeeId


And if I go for approach 2 I can make it with 2 tables

Table :Company

Id

Table :Employee
Id CompanyId


Avoiding a table join means performance gain. ie, with approach 2 i get better performance at the cost of class modeling.


Is this scenario valid ? What would be your option in this context?
Please let me know
Re: Using OneToMany or ManyToOne . A Performance issue [message #647082 is a reply to message #646419] Tue, 04 January 2011 14:28 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1021
Registered: July 2009
Senior Member
Hello,

This question is more a database design question, not an object modeling question. If you want a company to have a list of Employee's, this can be done regardless of there being a join table or not - ie you can use
@OneToMany
List<Employee> employees;

Or
@OneToMany
@JoinColumn(name="FK_COMPANY_ID")
List<Employee> employees;

The second option uses a foreign key "FK_COMPANY_ID" in the Employee table. So there is no cost to object modeling - other than when accessing the list, it will cause a query on the Employee table for associated Employees.

Best Regards,
Chris



Previous Topic:problems using metamodel generator in Eclipse
Next Topic:FK value setting in a ManyToOne relationship
Goto Forum:
  


Current Time: Wed Sep 17 19:37:07 GMT 2014

Powered by FUDForum. Page generated in 0.02846 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software