• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert HashMap to HashSet for @OneToMany for JPA Hibernate Implementation

 
Rithanya Laxmi
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Rithanya Laxmi
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys any update on this?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic