Here is the stripped down version of my code:
@Entity
public class Item implements Serializable{
@Id
@GeneratedValue
private long id;
@ElementCollection(fetch=FetchType.EAGER ,targetClass=Cost.class)
@CollectionTable(name="ItemCost", joinColumns = {@JoinColumn(name="itemId")})
private Set<Cost> costs= new HashSet<Cost>();
@ElementCollection(fetch=FetchType.EAGER ,targetClass=ItemLocation.class)
@CollectionTable(name="ItemLocation", joinColumns = {@JoinColumn(name="itemId")})
private Set<ItemLocation> itemLocations;
}
Is the above code allowed? I have two embeddable classes Cost and ItemLocation that I am using with @ElementCollection.
Issue: When I try to run a named query
@NamedQuery(name = "Item.findAll", query = "SELECT i FROM Item i")
I have strange behavior. The records in the second elementcollection (ItemLccation table) are getting doubled (inserted into the table).