Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!