Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert HashMap to HashSet for @OneToMany for JPA Hibernate Implementation

User_19BPUAug 5 2013 — edited Aug 13 2013

Hi,

I have a HashMap with @OneToMany relationship as shown below:-


@Entity
Class CustomerDetails {

....

  @OneToMany(fetch = FetchType.EAGER)
  @JoinTable(name="Cust_Order")
  @MapKeyColumn(name="orders_number")
  
   public Map<String,Order> getOrders() { return orders; }
   public void setOrders(Map<String,Order> orders) { this.orders = orders; }
   private Map<String,Order> orders;
  
   // getters & setters for orders
  
}


This class does have "N" number of @OneToMany relationships which is represented as "HashMap" and I want all of them to be eagerly loaded.Where it throws HibernateException "Cannot simultaneously fetch Multiple Bags" this is due to multiple collections in CustomerDetails
with fetchType as "EAGER". Now I want to convert my collection type from HashMap to HashSet so that I can resolve this problem? Please let me know how I can convert HashMap to HashSet as HashMap takes key,value pairs unlike HashSet?

private Map<String,Order> orders;

to

private Set<Order> orders;

Please clarify the above & is there any better way to do it?

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 10 2013
Added on Aug 5 2013
1 comment
1,922 views