JPA References an Unknown Entity

Asked

Viewed 301 times

0

I have the following scenario:

Class Rpsv3vo:

package nfse.vo;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

/**
 *
 * @author Administrador
 * Representa a estrutura do Recibo Provisório de Serviço (RPS)
 */
@Entity
@Table(name="Rps")
@XmlType(name = "tcRps", propOrder={
    "infRps"
})
public class RpsV3Vo implements Serializable
{
    // atributos
    private Integer id;
    private InfRpsV3Vo infRps;
    private LoteRpsV3Vo.ListaRps listaRps;

    // construtor padrão
    public RpsV3Vo() {
    }

    // métodos
    @Override
    public String toString() {
        return "RpsV3Vo{" + "id=" + id + ", infRps=" + infRps + ", listaRps=" + listaRps + '}';
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 37 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RpsV3Vo other = (RpsV3Vo) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    // getters e setters
    @Id
    @Column
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @XmlTransient
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "infRpsId", referencedColumnName = "id",
            nullable = false, foreignKey = @ForeignKey(name = "fkRpsInfRps"))
    @XmlElement(name = "InfRps", required = true)
    public InfRpsV3Vo getInfRps() {
        return infRps;
    }

    public void setInfRps(InfRpsV3Vo InfRps) {
        this.infRps = InfRps;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @XmlTransient
    public LoteRpsV3Vo.ListaRps getListaRps() {
        return listaRps;
    }

    public void setListaRps(LoteRpsV3Vo.ListaRps listaRps) {
        this.listaRps = listaRps;
    }

}

Loterpsv3vo class:

package nfse.vo;

import java.io.Serializable;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.persistence.AssociationOverride;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name="LoteRps")
@XmlType(name = "tcLoteRps", propOrder={
    "numeroLote",
    "cnpj",
    "inscricaoMunicipal",
    "quantidadeRps",
    "listaRps"

})
public class LoteRpsV3Vo implements Serializable
{
    // atributos
    private String id;
    private BigInteger numeroLote;
    private String cnpj;
    private String inscricaoMunicipal;
    private Integer quantidadeRps;
    private LoteRpsV3Vo.ListaRps listaRps;
    private LocalDateTime dataRecebimento;
    private String protocolo;
    private byte situacao;
    private MensagemRetornoV3Vo mensagemRetorno;

    // construtor padrão
    public LoteRpsV3Vo() {
    }

    // métodos
    @Override
    public String toString() {
        return "LoteRpsV3Vo{" + "id=" + id + ", numeroLote=" + numeroLote + ", cnpj=" + cnpj + ", inscricaoMunicipal=" + inscricaoMunicipal + ", quantidadeRps=" + quantidadeRps + ", listaRps=" + listaRps + ", dataRecebimento=" + dataRecebimento + ", protocolo=" + protocolo + ", situacao=" + situacao + ", mensagemRetorno=" + mensagemRetorno + '}';
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 29 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final LoteRpsV3Vo other = (LoteRpsV3Vo) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    // getters e setters
    @Id
    @Column(nullable = false, length = 255, unique = true)
    @XmlAttribute(name = "Id")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(nullable = false, length = 15, unique = true)
    @XmlElement(name = "NumeroLote", required = true)
    @XmlSchemaType(name = "nonNegativeInteger")
    public BigInteger getNumeroLote() {
        return numeroLote;
    }

    public void setNumeroLote(BigInteger numeroLote) {
        this.numeroLote = numeroLote;
    }

    @Column(nullable = false, length = 14)
    @XmlElement(name = "Cnpj", required = true)
    public String getCnpj() {
        return cnpj;
    }

    public void setCnpj(String cnpj) {
        this.cnpj = cnpj;
    }

    @Column(nullable = false, length = 15)
    @XmlElement(name = "InscricaoMunicipal", required = true)
    public String getInscricaoMunicipal() {
        return inscricaoMunicipal;
    }

    public void setInscricaoMunicipal(String inscricaoMunicipal) {
        this.inscricaoMunicipal = inscricaoMunicipal;
    }

    @Column(nullable = false, length = 4)
    @XmlElement(name = "QuantidadeRps")
    public Integer getQuantidadeRps() {
        return quantidadeRps;
    }

    public void setQuantidadeRps(Integer quantidadeRps) {
        this.quantidadeRps = quantidadeRps;
    }

    @XmlElement(name = "ListaRps", required = true)
    @Embedded
    public ListaRps getListaRps() {
        return listaRps;
    }

    public void setListaRps(ListaRps listaRps) {
        this.listaRps = listaRps;
    }

    @Column
    @XmlTransient
    public LocalDateTime getDataRecebimento() {
        return dataRecebimento;
    }

    public void setDataRecebimento(LocalDateTime dataRecebimento) {
        this.dataRecebimento = dataRecebimento;
    }

    @Column
    @XmlTransient
    public String getProtocolo() {
        return protocolo;
    }

    public void setProtocolo(String protocolo) {
        this.protocolo = protocolo;
    }

    @Column
    @XmlTransient
    public byte getSituacao() {
        return situacao;
    }

    public void setSituacao(byte situacao) {
        this.situacao = situacao;
    }

    @OneToOne(mappedBy = "loteRps", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
    @XmlTransient
    public MensagemRetornoV3Vo getMensagemRetorno() {
        return mensagemRetorno;
    }

    public void setMensagemRetorno(MensagemRetornoV3Vo mensagemRetorno) {
        this.mensagemRetorno = mensagemRetorno;
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "rps"
    })
    @Embeddable
    public static class ListaRps
    {
        // atributos
        @XmlElement(name = "Rps", required = true)
        @OneToMany(mappedBy = "listaRps",cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
        protected List<RpsV3Vo> rps;

        // métodos
        public List<RpsV3Vo> getRps() {
            if (rps == null) {
                rps = new ArrayList<>();
            }
            return this.rps;
        }

        public void setRps(List<RpsV3Vo> rps) {
            this.rps = rps;
        }

    }

}

When running this application, I get the following error:

org.hibernate.Annotationexception: @Onetoone or @Manytoone on nfse.vo.Rpsv3vo.listaRps References an Unknown Entity: nfse.vo.Loterpsv3vo$Listarps

Someone might be able to help me ?

  • You don’t have to put one @Embedded in listaRps class RpsV3Vo?

  • I put... The error remains the same. But thanks for helping Renan

No answers

Browser other questions tagged

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