This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collections - Hibernate

 
Vinod Kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two POJOs, User and Factory.
I have three tables, t_user, t_factory and t_user_factory

t_user has user profile (primary key is user_id)
t_factory has factory details (primary key is factory_id)
t_user_factory has user's assigned factories (user_id and factory_id are only columns here). The reason why t_user is not having a factory_id is that t_user will have lot of redudant data as one user can have many factories.

How I can get list of factories for a user using Hibernate? I declared a Set of factories inside User object. If I use the following code in User.hbm.xml, it is not recognizing the USER_ID column,it says invalid column name.
<class name="User" table="t_user" lazy="true">
:
:
<set name="factories" table="t_user_factory" lazy="false">
<key column="USER_ID" />
<one-to-many class="Factory"/>
</set>

:
:
</class>

Thanks,
Vinod

[ March 06, 2008: Message edited by: Vinod Kumar ]
[ March 06, 2008: Message edited by: Vinod Kumar ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are looking to do is a one-to-many with join table mapping

The hibernate docs here

http://www.hibernate.org/hib_docs/v3/reference/en/html/associations.html#assoc-unidirectional-join-12m

Go through how you map one-to-many and many-to-one with a join table

Good Luck

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic