• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add one element to collection without loading?

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic