GARANTIR DESCONTO

Fórum Error EmbeddedID jpa Hibernate #571878

30/11/2016

0

Pessoal estou com o seguinte problema, preciso de um joinTable onde na tabela de mapeamento eu preciso ter um terceiro campo para mostrar a quantidade de relacoes o objeto cliente possui com o objeto garrafao. Porem na tabela de mapeamente da o seguinte erro na anotacao @EmbeddedId:
Embedded ID class should not contain relationship mappings.
Essas são as minhas classes:

@Entity
@Table(name = "cliente_garrafao", catalog = "clienteGarrafao")
@AssociationOverrides({
		@AssociationOverride(name = "pk.cliente",
			joinColumns = @JoinColumn(name = "CLIENTE_ID")),
		@AssociationOverride(name = "pk.garrafao",
			joinColumns = @JoinColumn(name = "GARRAFAO_ID")) })
public class ClienteGarrafao implements java.io.Serializable {

	private ClienteGarrafaoId pk = new ClienteGarrafaoId();
	private int quantidade;

	public ClienteGarrafao() {
	}

	@EmbeddedId
	public ClienteGarrafaoId getPk() {
		return pk;
	}

	public void setPk(ClienteGarrafaoId pk) {
		this.pk = pk;
	}

	@Transient
	public Cliente getCliente() {
		return getPk().getCliente();
	}

	public void setCliente(Cliente cliente) {
		getPk().setCliente(cliente);
	}

	@Transient
	public Garrafao getGarrafao() {
		return getPk().getGarrafao();
	}

	public void setGarrafao(Garrafao garrafao) {
		getPk().setGarrafao(garrafao);
	}

	@Column(name = "QUANTIDADE", nullable = false, length = 10)
	public int getQuantidade() {
		return this.quantidade;
	}

	public void setQuantidade(int quantidade) {
		this.quantidade = quantidade;
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		ClienteGarrafao that = (ClienteGarrafao) o;

		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;

		return true;
	}

	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}
}


@Embeddable
public class ClienteGarrafaoId implements java.io.Serializable {

	private Cliente cliente;
    private Garrafao garrafao;

	@ManyToOne
	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	@ManyToOne
	public Garrafao getGarrafao() {
		return garrafao;
	}

	public void setGarrafao(Garrafao garrafao) {
		this.garrafao = garrafao;
	}

	public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ClienteGarrafaoId that = (ClienteGarrafaoId) o;

        if (cliente != null ? !cliente.equals(that.cliente) : that.cliente != null) return false;
        if (garrafao != null ? !garrafao.equals(that.garrafao) : that.garrafao != null)
            return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (cliente != null ? cliente.hashCode() : 0);
        result = 31 * result + (garrafao != null ? garrafao.hashCode() : 0);
        return result;
    }

}
Natanael Aguiar

Natanael Aguiar

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar