Tenho uma view com as colunas CD_CLIENTE (INT), DS_RAZAO_SOCIAL (String) e ANO_MES_INCLUSAO (String) , infelizmente essa view não tem uma primary key.
O NetBeans gerou para mim o arquivo de persistencia, porém como a view não tem uma Primary Key, o resultado das querys vieram duplicadas (setando CD_CLIENTE como pk). Não posso usar nenhuma das colunas como PK pois elas se repetem, por isso estou tentando criar uma PK da junção do CD_CLIENTE com ANO_MES_INCLUSAO, porém não estou conseguindo.
O erro está acontecendo em uma classe que já existe e eu nem mexi (RelatorioUsuarioPK), sendo que a classe que eu criei chama CodClienteAnoMesPK. A aplicação estava rodando normalmente antes da inclusão dessas novas classes.
Segue o erro ao tentar subir a aplicação:
Error occurred during deployment: Exception while preparing the app : (class: br/com/teste/entity/RelatorioUsuarioPK, method: signature: (II)V) Constructor must call super() or this(). Please see server.log for more details.
Segue os codigos:
CodClienteAnoMesPK
[code]@Embeddable
public class CodClienteAnoMesPK implements Serializable {
@Basic(optional = false)
@NotNull
@Column(name = "CD_CLIENTE")
private short cdCliente;
@Size(max = 6)
@Column(name = "ANO_MES_INCLUSAO")
private String anoMesInclusao;
public CodClienteAnoMesPK() {
}
public CodClienteAnoMesPK(short cdCliente, String anoMesInclusao) {
this.cdCliente = cdCliente;
this.anoMesInclusao = anoMesInclusao;
}
public short getCdCliente() {
return cdCliente;
}
public void setCdCliente(short cdCliente) {
this.cdCliente = cdCliente;
}
public String getAnoMesInclusao() {
return anoMesInclusao;
}
public void setAnoMesInclusao(String anoMesInclusao) {
this.anoMesInclusao = anoMesInclusao;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) cdCliente;
hash += (int) anoMesInclusao.hashCode();
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof CodClienteAnoMesPK)) {
return false;
}
CodClienteAnoMesPK other = (CodClienteAnoMesPK) object;
if (this.cdCliente != other.cdCliente) {
return false;
}
if (this.anoMesInclusao != other.anoMesInclusao) {
return false;
}
return true;
}[/code]
O codigo da view gerado pelo NetBeans
[code]
@Entity
@Table(name = “VW_REL_QTDE_NFE”)
@XmlRootElement
@NamedQueries({
@NamedQuery(name = “VwRelQtdeNfe.findAll”, query = “SELECT v FROM VwRelQtdeNfe v”),
@NamedQuery(name = “VwRelQtdeNfe.findByCdCliente”, query = “SELECT v FROM VwRelQtdeNfe v WHERE v.codClienteAnoMesPK.cdCliente = :cdCliente”),
@NamedQuery(name = “VwRelQtdeNfe.findByDsRazaoSocial”, query = “SELECT v FROM VwRelQtdeNfe v WHERE v.dsRazaoSocial = :dsRazaoSocial”),
@NamedQuery(name = “VwRelQtdeNfe.findByAnoMesInclusao”, query = “SELECT v FROM VwRelQtdeNfe v WHERE v.codClienteAnoMesPK.anoMesInclusao = :anoMesInclusao”),
@NamedQuery(name = “VwRelQtdeNfe.findBySumNfe”, query = “SELECT v FROM VwRelQtdeNfe v WHERE v.sumNfe = :sumNfe”)})
public class VwRelQtdeNfe implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected CodClienteAnoMesPK codClienteAnoMesPK;
@Basic(optional = false)
@NotNull
@Column(name = “CD_CLIENTE”)
private short cdCliente;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 100)
@Column(name = “DS_RAZAO_SOCIAL”)
private String dsRazaoSocial;
@Size(max = 6)
@Column(name = “ANO_MES_INCLUSAO”)
private String anoMesInclusao;
@Column(name = “SUM_NFE”)
private BigInteger sumNfe;
public VwRelQtdeNfe() {
}
public short getCdCliente() {
return cdCliente;
}
public void setCdCliente(short cdCliente) {
this.cdCliente = cdCliente;
}
public String getDsRazaoSocial() {
return dsRazaoSocial;
}
public void setDsRazaoSocial(String dsRazaoSocial) {
this.dsRazaoSocial = dsRazaoSocial;
}
public String getAnoMesInclusao() {
return anoMesInclusao;
}
public void setAnoMesInclusao(String anoMesInclusao) {
this.anoMesInclusao = anoMesInclusao;
}
public BigInteger getSumNfe() {
return sumNfe;
}
public void setSumNfe(BigInteger sumNfe) {
this.sumNfe = sumNfe;
}
/* ------------- PK ----------------*/
public VwRelQtdeNfe(CodClienteAnoMesPK codClienteAnoMesPK) {
this.codClienteAnoMesPK = codClienteAnoMesPK;
}
public CodClienteAnoMesPK getCodClienteAnoMesPK() {
return codClienteAnoMesPK;
}
public void setCodClienteAnoMesPK(CodClienteAnoMesPK codClienteAnoMesPK) {
this.codClienteAnoMesPK = codClienteAnoMesPK;
}
@Override
public int hashCode() {
int hash = 0;
hash += (codClienteAnoMesPK != null ? codClienteAnoMesPK.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof VwRelQtdeNfe)) {
return false;
}
VwRelQtdeNfe other = (VwRelQtdeNfe) object;
if ((this.codClienteAnoMesPK == null && other.codClienteAnoMesPK != null) || (this.codClienteAnoMesPK != null && !this.codClienteAnoMesPK.equals(other.codClienteAnoMesPK))) {
return false;
}
return true;
}[/code]
Desculpe se está mal explicado, ainda sou novato e peguei esse projeto que ja estava pronto e estou criando uma nova funcionalidade nela.
Obrigado!