[RESOLVIDO]IDComposta Hibernate 3.6

3 respostas
Polverini

Bom Dia pessoal,

Me ajudem a entender como funciona a PKComposta no hibernate ?
Tenho essas duas classes mas não sei como trabalhar com elas (uma é o modelo e a outra o ID), Fiz engenharia reversa a partir do banco que criei na modelagem, Exemplo da ID que quero:

Ano 2011

0001/2011

Ano 2012

0001/2012

Com essas classes consigo isso ? Se sim como faço para trabalhar com elas (Como buscar por id por exemplo ou salvar).

package com.geco.model;
// Generated 04/03/2011 17:11:57 by Hibernate Tools 3.2.1.GA

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
 * AutorizacaoId generated by hbm2java
 */
@Embeddable
public class AutorizacaoId implements java.io.Serializable {

    private int id;
    private String ano;
    private int solicitacaoId;
    private String solicitacaoAno;
    private int usuarioId;
    private int contabilId;
    private int formapagId;

    public AutorizacaoId() {
    }

    public AutorizacaoId(int id, String ano, int solicitacaoId, String solicitacaoAno, int usuarioId, int contabilId, int formapagId) {
        this.id = id;
        this.ano = ano;
        this.solicitacaoId = solicitacaoId;
        this.solicitacaoAno = solicitacaoAno;
        this.usuarioId = usuarioId;
        this.contabilId = contabilId;
        this.formapagId = formapagId;
    }

    @Column(name = "ID", nullable = false)
    public int getId() {
        return this.id;
    }

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

    @Column(name = "ANO", nullable = false, length = 5)
    public String getAno() {
        return this.ano;
    }

    public void setAno(String ano) {
        this.ano = ano;
    }

    @Column(name = "SOLICITACAO_ID", nullable = false)
    public int getSolicitacaoId() {
        return this.solicitacaoId;
    }

    public void setSolicitacaoId(int solicitacaoId) {
        this.solicitacaoId = solicitacaoId;
    }

    @Column(name = "SOLICITACAO_ANO", nullable = false, length = 5)
    public String getSolicitacaoAno() {
        return this.solicitacaoAno;
    }

    public void setSolicitacaoAno(String solicitacaoAno) {
        this.solicitacaoAno = solicitacaoAno;
    }

    @Column(name = "USUARIO_ID", nullable = false)
    public int getUsuarioId() {
        return this.usuarioId;
    }

    public void setUsuarioId(int usuarioId) {
        this.usuarioId = usuarioId;
    }

    @Column(name = "CONTABIL_ID", nullable = false)
    public int getContabilId() {
        return this.contabilId;
    }

    public void setContabilId(int contabilId) {
        this.contabilId = contabilId;
    }

    @Column(name = "FORMAPAG_ID", nullable = false)
    public int getFormapagId() {
        return this.formapagId;
    }

    public void setFormapagId(int formapagId) {
        this.formapagId = formapagId;
    }

    public boolean equals(Object other) {
        if ((this == other)) {
            return true;
        }
        if ((other == null)) {
            return false;
        }
        if (!(other instanceof AutorizacaoId)) {
            return false;
        }
        AutorizacaoId castOther = (AutorizacaoId) other;

        return (this.getId() == castOther.getId())
                && ((this.getAno() == castOther.getAno()) || (this.getAno() != null && castOther.getAno() != null && this.getAno().equals(castOther.getAno())))
                && (this.getSolicitacaoId() == castOther.getSolicitacaoId())
                && ((this.getSolicitacaoAno() == castOther.getSolicitacaoAno()) || (this.getSolicitacaoAno() != null && castOther.getSolicitacaoAno() != null && this.getSolicitacaoAno().equals(castOther.getSolicitacaoAno())))
                && (this.getUsuarioId() == castOther.getUsuarioId())
                && (this.getContabilId() == castOther.getContabilId())
                && (this.getFormapagId() == castOther.getFormapagId());
    }

    public int hashCode() {
        int result = 17;

        result = 37 * result + this.getId();
        result = 37 * result + (getAno() == null ? 0 : this.getAno().hashCode());
        result = 37 * result + this.getSolicitacaoId();
        result = 37 * result + (getSolicitacaoAno() == null ? 0 : this.getSolicitacaoAno().hashCode());
        result = 37 * result + this.getUsuarioId();
        result = 37 * result + this.getContabilId();
        result = 37 * result + this.getFormapagId();
        return result;
    }
}
package com.geco.model;
// Generated 04/03/2011 17:11:57 by Hibernate Tools 3.2.1.GA

import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Autorizacao generated by hbm2java
 */
@Entity
@Table(name = "autorizacao", catalog = "mydb")
public class Autorizacao implements java.io.Serializable {

    private AutorizacaoId id;
    private Usuario usuario;
    private Formapag formapag;
    private Solicitacao solicitacao;
    private Contabil contabil;
    private Date abertura;
    private Date finalizacao;
    private String situacao;
    private Set<Pedido> pedidos = new HashSet<Pedido>(0);

    public Autorizacao() {
    }

    public Autorizacao(AutorizacaoId id, Usuario usuario, Formapag formapag, Solicitacao solicitacao, Contabil contabil, Date abertura, String situacao) {
        this.id = id;
        this.usuario = usuario;
        this.formapag = formapag;
        this.solicitacao = solicitacao;
        this.contabil = contabil;
        this.abertura = abertura;
        this.situacao = situacao;
    }

    public Autorizacao(AutorizacaoId id, Usuario usuario, Formapag formapag, Solicitacao solicitacao, Contabil contabil, Date abertura, Date finalizacao, String situacao, Set<Pedido> pedidos) {
        this.id = id;
        this.usuario = usuario;
        this.formapag = formapag;
        this.solicitacao = solicitacao;
        this.contabil = contabil;
        this.abertura = abertura;
        this.finalizacao = finalizacao;
        this.situacao = situacao;
        this.pedidos = pedidos;
    }

    @EmbeddedId
    @AttributeOverrides({
        @AttributeOverride(name = "id", column =
        @Column(name = "ID", nullable = false)),
        @AttributeOverride(name = "ano", column =
        @Column(name = "ANO", nullable = false, length = 5)),
        @AttributeOverride(name = "solicitacaoId", column =
        @Column(name = "SOLICITACAO_ID", nullable = false)),
        @AttributeOverride(name = "solicitacaoAno", column =
        @Column(name = "SOLICITACAO_ANO", nullable = false, length = 5)),
        @AttributeOverride(name = "usuarioId", column =
        @Column(name = "USUARIO_ID", nullable = false)),
        @AttributeOverride(name = "contabilId", column =
        @Column(name = "CONTABIL_ID", nullable = false)),
        @AttributeOverride(name = "formapagId", column =
        @Column(name = "FORMAPAG_ID", nullable = false))})
    public AutorizacaoId getId() {
        return this.id;
    }

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

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "USUARIO_ID", nullable = false, insertable = false, updatable = false)
    public Usuario getUsuario() {
        return this.usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FORMAPAG_ID", nullable = false, insertable = false, updatable = false)
    public Formapag getFormapag() {
        return this.formapag;
    }

    public void setFormapag(Formapag formapag) {
        this.formapag = formapag;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name = "SOLICITACAO_ID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false),
        @JoinColumn(name = "SOLICITACAO_ANO", referencedColumnName = "ANO", nullable = false, insertable = false, updatable = false)})
    public Solicitacao getSolicitacao() {
        return this.solicitacao;
    }

    public void setSolicitacao(Solicitacao solicitacao) {
        this.solicitacao = solicitacao;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CONTABIL_ID", nullable = false, insertable = false, updatable = false)
    public Contabil getContabil() {
        return this.contabil;
    }

    public void setContabil(Contabil contabil) {
        this.contabil = contabil;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "ABERTURA", nullable = false, length = 10)
    public Date getAbertura() {
        return this.abertura;
    }

    public void setAbertura(Date abertura) {
        this.abertura = abertura;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "FINALIZACAO", length = 10)
    public Date getFinalizacao() {
        return this.finalizacao;
    }

    public void setFinalizacao(Date finalizacao) {
        this.finalizacao = finalizacao;
    }

    @Column(name = "SITUACAO", nullable = false, length = 65)
    public String getSituacao() {
        return this.situacao;
    }

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

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "autorizacao")
    public Set<Pedido> getPedidos() {
        return this.pedidos;
    }

    public void setPedidos(Set<Pedido> pedidos) {
        this.pedidos = pedidos;
    }
}

3 Respostas

P

da uma olhada

http://www.guj.com.br/java/235340-mapeamento-duas-uk-na-mesma-tabela-hibernate-resolvido

ViniGodoy

Olá.

Evite escrever a palavra [DUVIDA] antes do título do tópico.
99% dos tópicos do fórum já são para tirar dúvidas, então, ajude a deixar em evidência a palavra [RESOLVIDO] não colocando o óbvio no título.

Polverini

Opa bobiei moderador, malz ae.

paribe:
da uma olhada

http://www.guj.com.br/java/235340-mapeamento-duas-uk-na-mesma-tabela-hibernate-resolvido

Opa vai me ajudar bem vlw

Realmente sanou minhas duvidas, muito obrigado !

Criado 10 de março de 2011
Ultima resposta 14 de mar. de 2011
Respostas 3
Participantes 3