Incomplete entity class problem - JPA

Asked

Viewed 339 times

1

Personal I am trying to make the relationship between two class (Cotdetatlhe and Cotdetforn), but I am 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 a Composite Primary key, a @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.

Just 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;
  • What’s the Cotdetatlhepk class code? To dry the question, it would also be interesting to clear fields that are not part of the problem (such as Double attributes, for example)

  • Vlw by @Dherik tip, I already dried the code, only with the necessary and posted the code of the Cotdetatlhepk Table

2 answers

1

You are trying to reference a Cotdetatlhe entity that has probably composite 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 cotDetatte relationship in Cotdetforn, you weren’t trying to reference the PK composed of Cotdetatlhe.

  • then in the case inside @Joincolumns in Cotdetforn I put the fields of Cotdetatlhepk is this?

1

Guys I solved my problem like this:

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;

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

http://docs.oracle.com/cd/B32110_01/web.1013/b28221/cmp30cfg001.htm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.