samedi 25 juin 2016

How mapping @ManyToMany with primary key in extra table using java.util.List

If i do this;

public class Client{

    @Id
    @Column(columnDefinition = "CHAR(11)")
    private String cpf;

    @ManyToMany(cascade = CascadeType.ALL)
    private List<Address> addresses;
    //get set
}

.

public class Address{

    @Id
    private String zipCode;

    @Id
    private String number;

    @Id
    @Column(columnDefinition = "varchar(255) default 'DONT HAVE'")
    private String complement;
    //get set
}

... I have this mapping:

Image - Model using java.util.List with @ManyToMany

If i do this;

public class Client{

    @Id
    @Column(columnDefinition = "CHAR(11)")
    private String cpf;

    @ManyToMany(cascade = CascadeType.ALL)
    private Set<Address> addresses;
    //get set
}

.

public class Address{

    @Id
    private String zipCode;

    @Id
    private String number;

    @Id
    @Column(columnDefinition = "varchar(255) default 'DONT HAVE'")
    private String complement;
    //get set
}

... I have this mapping:

Image - Model using java.util.Set with @ManyToMany

The Question is: how do I get the attributes of the extra table automatically generated by @ManyToMany relationship are primary foreign keys(PFK) using java.util.List?

Aucun commentaire:

Enregistrer un commentaire