The moose likes Object Relational Mapping and the fly likes How to add one element to collection without loading? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "How to add one element to collection without loading?" Watch "How to add one element to collection without loading?" New topic
Author

How to add one element to collection without loading?

avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
Hey,

Lets say i have - Department
Department has a List of Emploee (@OneToMany).

I want to add one emploee to the list withot loading the whole collection.

department.getEmployee().add(emploee)
will load the collection and it is bad if i have a big collection.


Thank you
Mike Keith
author
Ranch Hand

Joined: Jul 14, 2005
Posts: 304
Well in theory, assuming the OneToMany from Department to Employee is lazy and you have not accessed or triggered the employees relationship, then if you just set the ManyToOne from your Employee to its department and commit then you should accomplish what you want. No guarantees, though, since different vendors may do different things with caching, etc.


-Mike
Pro JPA 2: Mastering the Java Persistence API
avihai marchiano
Ranch Hand

Joined: Jan 10, 2007
Posts: 342
I am using Hibernate.

If i mapped bidirectional and set only the many to one isnt it a problem with the cache?

I found out that in hibernate using bidirectional bags will not load the whole list.
 
 
subject: How to add one element to collection without loading?
 
Threads others viewed
Test Abilities
A question about the standard
Test Abilities
Test Abilities
Basic JPA @OneToMany / @ManyToOne mapping trouble (related to hibernate?)
developer file tools