I am currently using such code to add a new record to a set in my entity.
player = em.find(Player.class, playerId); player.getAvatarAttributeOwnership().add(new AvatarAttributeOwnership(...));
It works, but every time I want to add one item, the whole set loads.
- Is there a way (possibly with a request) to add an item without loading the rest? In SQL, it will be something like
INSERT INTO AvatarAttributeOwnership(player, data, ...) VALUES({player}, ...); Uniqueness is currently maintained by the Set and AvatarAttributeOwnership.equals , but I assume this will not work anymore. How can I enforce it anyway?
I am using JPA2 + Hibernate. The code:
@Entity public class Player implements Serializable { @Id @GeneratedValue private long id; @ElementCollection(fetch=FetchType.LAZY)
source share