ManyToMany include other fields

0
Hello, I have a ManyToMany relationship between envio and carro , and I would like to understand how to save in the same table, which is created through this relationship, the entity id Local . >

Entidade Sending (through this relationship a table is created called car_export, with car id and id of the sending.)

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idEnvio")
private Integer id;

@Column(name = "dataEnvio")
@Temporal(javax.persistence.TemporalType.DATE)
private Date dataEnvio;

@Column(name = "dataRecebimentoLocal")
@Temporal(javax.persistence.TemporalType.DATE)
private Date dataRecebimentoLocal;

@Column(name = "dataDevolucao")
@Temporal(javax.persistence.TemporalType.DATE)
private Date dataDevolucao;

@ManyToOne
@JoinColumn(name = "envioCarro", referencedColumnName = "idCarro")
private Carro carro;
@ManyToOne
@JoinColumn(name = "envioLocall", referencedColumnName = "idLocal")
private Locall locall;

@ManyToMany
@JoinTable(name = "envio_carro", joinColumns
        = @JoinColumn(name = "envio_id"),
        inverseJoinColumns
        = @JoinColumn(name = "carro_id"))
private List<Carro> carros;

Entidade Car

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idCarro")
private Integer id;
@Column(name = "numeroCarro")
@ManyToMany(mappedBy = "carros")
private List<Envio> envios;

Entidade Local

@Entity
@DynamicUpdate(value=true)
@NamedQueries({
@NamedQuery(name = “Locall.findAll”, query = “SELECT distinct s FROM Locall s”),
@NamedQuery(name = “Locall.findByLocallId”, query = “SELECT s FROM Locall s WHERE s.id = :id”),
@NamedQuery(name = “Locall.findByLocallDescr”, query = “SELECT s FROM Locall s WHERE s.descricao = :descricao”)})
public class Locall implements Serializable, EntidadeBase {

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idLocal")
private Integer id;
@Column(name = "descricaoLocal")
private String descricao;
@OneToMany(mappedBy = "carro")
private List<Envio> envios;

I got through the examples here, to create ManyToMany , the doubt now is: it is possible (or even, correct) in this table (caused by ManyToMany ) to include id of Local , because I have several carros , being sent to multiple locais and each car is linked to envio , or do I have to change the approach?

    
asked by anonymous 07.12.2017 / 00:32

0 answers