@MapKey vs @MapKeyColumn

// @MapKey refers the field/property (unique one) in the Entity witch is the value of a Map field/property
// @MapKeyColumn refers the column in an @ElementCollection

@Entity
public class Person6 {
    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "person6")
    @MapKey(name = "address") // is the Address6's address property
    public Map<String, Address6> getAddress6Map() {
        return address6Map;
    }
...

@Entity
public class Address6 {
    private Integer id;
    private String address;
    private Person6 person6;
...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.