• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collections - Hibernate

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic