• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Quick question on hierarchical Entity Relationships....

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering whether EJB 3.0 supports hierarchical relationship in Entities. For example, you have an Employee table having EmpID and ManagerID columns, where ManagerID contains an employeeid of the manager of that employee.

How can we use 3.0 entities to model such relationship? Any idea?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ann Basso:
I am wondering whether EJB 3.0 supports hierarchical relationship in Entities. For example, you have an Employee table having EmpID and ManagerID columns, where ManagerID contains an employeeid of the manager of that employee.

How can we use 3.0 entities to model such relationship? Any idea?



Hi Ann,

i think this code represents the statements above:



I've omitted getter/setters and used public instance variables to focus on the problem.

Correct me if i was wrong!

Greetings,
Andor N�meth
 
Ann Basso
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is what I was thinking but I don't know whether that will work. For example, if you want to get all the employees that are managed by an employee, how will you get that?
[ August 09, 2007: Message edited by: Ann Basso ]
 
Andor Nemeth
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ann Basso:
Yes, that is what I was thinking but I don't know whether that will work. For example, if you want to get all the employees that are managed by an employee, how will you get that?

[ August 09, 2007: Message edited by: Ann Basso ]



The code example I've gave was for a many-to-one unidirectional relationship.
This way you can't determine directly the employees that are managed by an employee("manager").

For this you'll need obiviously a many-to-one bidirectional relationship:




Then I've created two methods in a session bean to play with this Employee class a bit:



Then I've created a client to locate my remote session bean and to call these two methods above!
After calling these methods this was the output on my JBoss console:

19:50:42,931 INFO [STDOUT] F�n�kJ�zsi's staff:
19:50:42,941 INFO [STDOUT] Munk�sB�la1
19:50:42,941 INFO [STDOUT] Munk�sB�la2


So, this is the soulution! It did work with this Employee class and with these annotations.


Greetings,
Andor N�meth

p.s.
It did take some time to accomplish this, because I run to this bug:
http://forum.java.sun.com/thread.jspa?threadID=5137725&tstart=60

[ August 09, 2007: Message edited by: Andor Nemeth ]
 
Ann Basso
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's amazing. Thanks a lot. I will also try to run in my app server.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!