Incomplete entity class problem - JPA

1

I'm trying to make the relationship between two classes (CotDetatlhe and CotDetForn), but I'm facing the following problem:

  

The @JoinColumns on the annotated element [field cotDetatlhe] from the entity class [class bean.CotDetForn] is incomplete. When the source entity class uses composite primary key, @JoinColumn must be specified for each join column using the @JoinColumns. Both the name and the referencedColumnName elements must be specified in each such @JoinColumn.

Below are the codes:

CotDetatlhe:

public class CotDetatlhe implements Serializable {
    @JoinColumns({
        @JoinColumn(name = "cod_req_cab", referencedColumnName = "cod_req_cab", insertable = false, updatable = false),
        @JoinColumn(name = "cod_produto", referencedColumnName = "cod_produto", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private ReqDet reqDet
    ///******* Relação com a classe CotDetForn
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cotDetatlhe")
    private Collection<CotDetForn> CotDetFornCollection;
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CotDetatlhePK cotDetatlhePK;
    @Basic(optional = false)
    @Column(name = "cod_req_det")
    private int codReqDet;
    @JoinColumn(name = "cod_cot_cab", referencedColumnName = "cod_cot_cab", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private CotCab cotCab;

CotDetForn:

public class CotDetForn implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CotDetFornPK cotDetFornPK;
    @Column(name = "desconto")
    private Integer desconto;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    ////**** Relação com a classe CotDetatlhe
    @JoinColumn(name = "cod_req_det", referencedColumnName = "cod_req_det", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private CotDetatlhe cotDetatlhe;

CotDetFornPK:

@Embeddable 
public class CotDetFornPK implements Serializable {
    @Basic(optional = false)
    @Column(name = "cod_det_forn")
    private int codDetForn;
    @Basic(optional = false)
    @Column(name = "cod_cot_forn")
    private int codCotForn;
    @Column(name = "cod_req_det")
    private int codReqDet;

CotDetatlhePK:

@Embeddable
public class CotDetatlhePK implements Serializable {
    @Basic(optional = false)
    @Column(name = "cod_cot_cab")
    private int codCotCab;
    @Basic(optional = false)
    @Column(name = "cod_req_cab")
    private int codReqCab;
    @Basic(optional = false)
    @Column(name = "cod_produto")
    private String codProduto;
    
asked by anonymous 27.03.2015 / 20:35

2 answers

1

You are trying to reference a CotDetatlhe entity that has a probably compound key (CotDetatlhePK).

If you want to relate CotDetatlhe from CotDetForn, you need to specify each CotDetatlhePK column as JoinColumn within a JoinColumns in CotDetForn.

The way you did the cotDetatlhe relationship in CotDetForn, you were not trying to reference CotDetatlhe's compound PK.

    
28.03.2015 / 13:43
1

Staff solved my problem as follows:

public class CotDetForn implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CotDetFornPK cotDetFornPK;

    //// troquei o @JoinColumn pelo @PrimaryKeyJoinColumn
    @PrimaryKeyJoinColumn(name = "cod_req_det", referencedColumnName = "cod_req_det")
    @ManyToOne(optional = false)
    private CotDetatlhe codReqDet;

I searched the forums and found this solution that has solved my problem so far.

link

    
07.04.2015 / 14:37