Modelagem PF PJ com Hibernate

Bom dia galera. Estou construindo um cadastro de Clientes. Criei a classe abstrata “pessoa” e as classes extend “pessoafisica” e “pessoa juricia”. Quero criar uma tabela pra cada.
Ao tentar salvar um cliente, dão os seguintes erros:

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2232)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at dao.HibernateUtil.commitTransaction(HibernateUtil.java:46)
at dao.DaoHibernateGenerico.save(DaoHibernateGenerico.java:18)
at controle.ClienteFisicaControle.salvar(ClienteFisicaControle.java:36)
at visao.ClienteCad.btSalvarActionPerformed(ClienteCad.java:585)
at visao.ClienteCad.access$200(ClienteCad.java:29)
at visao.ClienteCad$3.actionPerformed(ClienteCad.java:454)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:121)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1072)
at java.awt.Component.show(Component.java:1650)
at java.awt.Component.setVisible(Component.java:1602)
at java.awt.Window.setVisible(Window.java:1013)
at java.awt.Dialog.setVisible(Dialog.java:1003)
at visao.ClienteCad$8.run(ClienteCad.java:759)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.sql.BatchUpdateException: Entrada em lote 0 /* insert modelo.PessoaFisica */ insert into Pessoa (celular, cidade_id, email, endereco, nome, telefone, id) values (, 9, , , teste, , 26) foi abortada. Chame getNextException para ver a causa.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2537)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1328)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2674)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
… 76 more

Exception in thread “AWT-EventQueue-0” org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2232)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at dao.HibernateUtil.commitTransaction(HibernateUtil.java:46)
at dao.DaoHibernateGenerico.save(DaoHibernateGenerico.java:18)
at controle.ClienteFisicaControle.salvar(ClienteFisicaControle.java:36)
at visao.ClienteCad.btSalvarActionPerformed(ClienteCad.java:585)
at visao.ClienteCad.access$200(ClienteCad.java:29)
at visao.ClienteCad$3.actionPerformed(ClienteCad.java:454)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:121)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1072)
at java.awt.Component.show(Component.java:1650)
at java.awt.Component.setVisible(Component.java:1602)
at java.awt.Window.setVisible(Window.java:1013)
at java.awt.Dialog.setVisible(Dialog.java:1003)
at visao.ClienteCad$8.run(ClienteCad.java:759)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.sql.BatchUpdateException: Entrada em lote 0 /* insert modelo.PessoaFisica */ insert into Pessoa (celular, cidade_id, email, endereco, nome, telefone, id) values (, 9, , , teste, , 26) foi abortada. Chame getNextException para ver a causa.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2537)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1328)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:351)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2674)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
… 76 more
CONSTRUÍDO COM SUCESSO (tempo total: 14 segundos)

Seguem os códigos.

DAO:

public class DaoHibernateGenerico implements DaoGenerico {

    @Override
    public Object save(Object objeto) {
        try {
            Object obj = null;
            HibernateUtil.beginTransaction();
            obj = HibernateUtil.getSession().merge(objeto);
            HibernateUtil.commitTransaction();
            HibernateUtil.closeSession();
            return obj;
        } catch (HibernateException hibernateException) {
            HibernateUtil.rollbackTransaction();
            HibernateUtil.closeSession();
            throw hibernateException;
        }
    }

    @Override
    public void delete(Object objeto) {
        try {
            HibernateUtil.beginTransaction();
            HibernateUtil.getSession().delete(objeto);
            HibernateUtil.commitTransaction();
            HibernateUtil.closeSession();
        } catch (HibernateException hibernateException) {
            HibernateUtil.rollbackTransaction();
            throw new RuntimeException(hibernateException);
        }
    }

    public List list(Class clazz) {
        try {
            List lista = null;
            lista = HibernateUtil.getSession().createCriteria(clazz).list();
            return lista;
        } catch (HibernateException hibernateException) {
            HibernateUtil.rollbackTransaction();
            throw new RuntimeException(hibernateException);
        }
    }

    public Object getById(Serializable id, Class clazz) {
        try {
            Object obj = HibernateUtil.getSession().get(clazz, id);
            return obj;
        } catch (HibernateException hibernateException) {
            HibernateUtil.rollbackTransaction();
            throw new RuntimeException(hibernateException);
        }
    }

    public List listCriterio(Class clazz, String atributo, String criterio) {
        try {
            List lista = null;
            Criteria crit = HibernateUtil.getSession().createCriteria(clazz, atributo);
            crit.add(Restrictions.ilike(atributo, "%" + criterio + "%"));
            crit.addOrder(Order.asc(atributo));
            crit.setMaxResults(30);
            lista = crit.list();
            //HibernateUtil.closeSession();
            return lista;
        } catch (HibernateException hibernateException) {
            HibernateUtil.rollbackTransaction();
            throw new RuntimeException(hibernateException);
        }
    }
}[/code]

Pessoa
[code]

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
//@DiscriminatorColumn(name="TIPO")

public abstract class Pessoa implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column (length=255)
    private String nome;
    @Column (length=255)
    private String endereco;
    @OneToOne
    private Cidade cidade;
    @Column (length=10)
    private String telefone;
    @Column (length=10)
    private String celular;
    @Column (length=255)
    private String email;

    public String getCelular() {
        return celular;
    }

    public void setCelular(String celular) {
        this.celular = celular;
    }

    public Cidade getCidade() {
        return cidade;
    }

    public void setCidade(Cidade cidade) {
        this.cidade = cidade;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getTelefone() {
        return telefone;
    }

    public void setTelefone(String telefone) {
        this.telefone = telefone;
    }

    public Pessoa() {
    }



    public Long getId() {
        return id;
    }

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

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.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 Pessoa)) {
            return false;
        }
        Pessoa other = (Pessoa) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Pessoa[id=" + id + "]";
    }

}

[/code]

PessoaFisica
[code]@Entity
@Table(name="PessoaFisica")
//@DiscriminatorValue("FISICA")
public class PessoaFisica extends Pessoa implements Serializable{

    @Column(length = 11, unique=true, nullable=false)
    private String cpf;
    @Column(length = 15)
    private String rg;
    @Column(length = 8)
    private String cep;
    @Temporal(TemporalType.DATE)
    private Date aniversario;

    public PessoaFisica() {
    }

    public String toString() {
        return super.toString() + " " + cpf;
    }

    public Date getAniversario() {
        return aniversario;
    }

    public void setAniversario(Date aniversario) {
        this.aniversario = aniversario;
    }

    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }

    public String getCpf() {
        return cpf;
    }

    public void setCpf(String cpf) {
        this.cpf = cpf;
    }

    public String getRg() {
        return rg;
    }

    public void setRg(String rg) {
        this.rg = rg;
    }

    
}

Pessoa Jurídica

[code]@Entity
@Table(name=“PessoaJuridica”)
//@DiscriminatorValue(“JURIDICA”)
public class PessoaJuridica extends Pessoa implements Serializable {

@Column(length = 14, unique=true, nullable=false)
private String cnpj;
@Column(length = 15)
private String inscricao;
@Column(length = 8)
private String cep;
@Temporal(TemporalType.DATE)
private Date constituicao;

public PessoaJuridica() {
}

public String toString() {
    return super.toString() + " " + cnpj;
}

public String getCep() {
    return cep;
}

public void setCep(String cep) {
    this.cep = cep;
}

public String getCnpj() {
    return cnpj;
}

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

public Date getConstituicao() {
    return constituicao;
}

public void setConstituicao(Date constituicao) {
    this.constituicao = constituicao;
}

public String getInscricao() {
    return inscricao;
}

public void setInscricao(String inscricao) {
    this.inscricao = inscricao;
}

}
[/code]

ClienteCad

[code]
Package visao;

import modelo.Cidade;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import controle.CidadeControle;
import controle.ClienteFisicaControle;
import controle.ClienteJuridicaControle;
import modelo.PessoaFisica;
import modelo.PessoaJuridica;
import java.util.Date;

/**
*

  • @author aluno
    */
    public class ClienteCad extends javax.swing.JDialog {

    private Cidade cid;
    private List listaCid = new ArrayList();
    private List listaPF = new ArrayList();
    private List listaPJ = new ArrayList();
    private PessoaFisica pf;
    private PessoaJuridica pj;
    private CidadeControle cidcontrole;
    private ClienteFisicaControle pfControle;
    private ClienteJuridicaControle pjControle;
    public int i;

    public void validaBotoes(String acao) {
    if (acao.equals(“inicio”)) {
    //setEnabled habilita ou desabilita o botão ou tabela.
    btNovo.setEnabled(true);
    btSalvar.setEnabled(false);
    btExcluir.setEnabled(false);
    btAlterar.setEnabled(false);
    btCancelar.setEnabled(false);
    btSair.setEnabled(true);
    //setEditable habilita ou desabilita os campos.
    campoNome.setEditable(false);
    comboCidade.setEnabled(false);
    campoDoc1.setEditable(false);
    campoDoc2.setEditable(false);
    campoEndereco.setEditable(false);
    campoCelular.setEditable(false);
    campoCep.setEditable(false);
    campoEmail.setEditable(false);
    campoTelefone.setEditable(false);

         comboCidade.setEnabled(false);
         painelTabela.setEnabled(false);
         fFiltro.setEnabled(true);
         tabela.setEnabled(true);
     } else if (acao.equals("novo") || acao.equals("alterar")) {
         btNovo.setEnabled(false);
         btSalvar.setEnabled(true);
         btExcluir.setEnabled(false);
         btAlterar.setEnabled(false);
         btCancelar.setEnabled(true);
         btSair.setEnabled(false);
    
    
         campoNome.setEditable(true);
         comboCidade.setEnabled(true);
         campoDoc1.setEditable(true);
         campoDoc2.setEditable(true);
         campoEndereco.setEditable(true);
         campoCelular.setEditable(true);
         campoCep.setEditable(true);
         campoEmail.setEditable(true);
         campoTelefone.setEditable(true);
    
    
         painelTabela.setEnabled(false);
         tabela.setEnabled(false);
         fFiltro.setEnabled(false);
     } else if (acao.equals("selecionado")) {
    
         btNovo.setEnabled(true);
         btSalvar.setEnabled(false);
         btExcluir.setEnabled(true);
         btAlterar.setEnabled(true);
         btCancelar.setEnabled(true);
         btSair.setEnabled(true);
    
         campoNome.setEditable(false);
         comboCidade.setEnabled(false);
         campoDoc1.setEditable(false);
         campoDoc2.setEditable(false);
         campoEndereco.setEditable(false);
         campoCelular.setEditable(false);
         campoCep.setEditable(false);
         campoEmail.setEditable(false);
         campoTelefone.setEditable(false);
    
    
         painelTabela.setEnabled(true);
         tabela.setEnabled(true);
         fFiltro.setEnabled(true);
     }
    

    }

    //Valida os campos obrigatórios de um cadastro,
    //retornando um boolean true quando verdadeiro ou false quando tiver algum campo em branco.
    public Boolean validaCampos() {
    if (campoNome.getText().equals("")) {
    //exibe uma mensagem para o usuario.
    JOptionPane.showMessageDialog(null, “O campo nome da cidade é obrigatório!”);
    return false;
    } else if (comboCidade.getSelectedItem() == null) {
    JOptionPane.showMessageDialog(null, “A combo estado é obrigatório!”);
    return false;
    } else {
    return true;
    }
    }

    public void limpaCampos() {
    campoCelular.setText("");
    campoCep.setText("");
    campoData.setText("");
    campoDoc1.setText("");
    campoDoc2.setText("");
    campoEmail.setText("");
    campoNome.setText("");
    campoEndereco.setText("");
    campoTelefone.setText("");
    comboCidade.setSelectedItem(null);

    }

    // Monta uma combo com seus itens.
    public void montaCombo() {
    comboCidade.removeAllItems();
    listaCid = cidcontrole.listaTodos();
    for (Cidade ci : listaCid) {
    comboCidade.addItem(ci.getNome() + " - " + ci.getEstado().getSigla());
    }
    }
    //Monta a tabela com todas as cidades cadastradas no banco.

    public void montaTabela() {
    List listaCli = new ArrayList();
    listaCli.add(pfControle.listaTodos());
    listaCli.add(pjControle.listaTodos());
    DefaultTableModel modelo = new DefaultTableModel();
    modelo.addColumn(“ID”);
    modelo.addColumn(“Nome/Razão”);
    modelo.addColumn(“CPF/CNPJ”);
    modelo.addColumn(“Telefone”);
    modelo.addColumn(“Celular”);
    modelo.addColumn(“email”);
    for (PessoaFisica p : listaPF) {
    modelo.addRow(new Object[]{p.getId(), p.getNome(), p.getCpf(), p.getTelefone(), p.getCelular(), p.getEmail()});
    }
    for (PessoaJuridica j : listaPJ) {
    modelo.addRow(new Object[]{j.getId(), j.getNome(), j.getCnpj(), j.getTelefone(), j.getCelular(), j.getEmail()});
    tabela.setModel(modelo);
    }
    }

    /** Creates new form ClienteCad */
    public ClienteCad(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    pfControle = pfControle.getInstance();
    pjControle = pjControle.getInstance();
    cidcontrole= CidadeControle.getInstance();
    painelDados.setVisible(false);
    comboPFPJ.setEnabled(false);
    btInicia.setEnabled(false);
    }

    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      */
      @SuppressWarnings(“unchecked”)
      //
      private void initComponents() {

      buttonGroup1 = new javax.swing.ButtonGroup();
      jPanel1 = new javax.swing.JPanel();
      painelDados = new javax.swing.JPanel();
      jLabel1 = new javax.swing.JLabel();
      rotuloNome = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      jLabel4 = new javax.swing.JLabel();
      jLabel5 = new javax.swing.JLabel();
      jLabel6 = new javax.swing.JLabel();
      jLabel7 = new javax.swing.JLabel();
      rotuloData = new javax.swing.JLabel();
      rotuloDoc1 = new javax.swing.JLabel();
      rotuloDoc2 = new javax.swing.JLabel();
      jLabel11 = new javax.swing.JLabel();
      campoCodigo = new javax.swing.JTextField();
      campoNome = new javax.swing.JTextField();
      campoEndereco = new javax.swing.JTextField();
      campoCep = new javax.swing.JTextField();
      campoTelefone = new javax.swing.JTextField();
      campoDoc1 = new javax.swing.JTextField();
      campoData = new javax.swing.JTextField();
      comboCidade = new javax.swing.JComboBox();
      campoCelular = new javax.swing.JTextField();
      campoDoc2 = new javax.swing.JTextField();
      campoEmail = new javax.swing.JTextField();
      jSeparator1 = new javax.swing.JSeparator();
      jSeparator2 = new javax.swing.JSeparator();
      painelTabela = new javax.swing.JPanel();
      jScrollPane1 = new javax.swing.JScrollPane();
      tabela = new javax.swing.JTable();
      jLabel2 = new javax.swing.JLabel();
      fFiltro = new javax.swing.JTextField();
      comboTipo = new javax.swing.JComboBox();
      btInicia = new javax.swing.JButton();
      btNovo = new javax.swing.JButton();
      btSalvar = new javax.swing.JButton();
      btExcluir = new javax.swing.JButton();
      btAlterar = new javax.swing.JButton();
      btCancelar = new javax.swing.JButton();
      btSair = new javax.swing.JButton();
      comboPFPJ = new javax.swing.JComboBox();

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

      painelDados.setBorder(javax.swing.BorderFactory.createTitledBorder(“Dados”));
      painelDados.setFont(new java.awt.Font(“Tahoma”, 1, 11));

      jLabel1.setText(“ID”);

      rotuloNome.setText(“Nome”);

      jLabel3.setText(“Endereco”);

      jLabel4.setText(“Cidade”);

      jLabel5.setText(“Cep”);

      jLabel6.setText(“Telefone”);

      jLabel7.setText(“Celular”);

      rotuloData.setText(“Data”);

      rotuloDoc1.setText(“Doc1”);

      rotuloDoc2.setText(“Doc2”);

      jLabel11.setText(“email”);

      campoCodigo.setEditable(false);

      comboCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Item 1”, “Item 2”, “Item 3”, “Item 4” }));

      painelTabela.setBorder(javax.swing.BorderFactory.createTitledBorder(“Tabela”));

      tabela.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
      {null, null, null, null},
      {null, null, null, null},
      {null, null, null, null},
      {null, null, null, null}
      },
      new String [] {
      “Title 1”, “Title 2”, “Title 3”, “Title 4”
      }
      ));
      jScrollPane1.setViewportView(tabela);

      javax.swing.GroupLayout painelTabelaLayout = new javax.swing.GroupLayout(painelTabela);
      painelTabela.setLayout(painelTabelaLayout);
      painelTabelaLayout.setHorizontalGroup(
      painelTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(painelTabelaLayout.createSequentialGroup()
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 840, Short.MAX_VALUE)
      .addContainerGap())
      );
      painelTabelaLayout.setVerticalGroup(
      painelTabelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(painelTabelaLayout.createSequentialGroup()
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      );

      jLabel2.setText(“Pesquisa”);

      comboTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Item 1”, “Item 2”, “Item 3”, “Item 4” }));

      javax.swing.GroupLayout painelDadosLayout = new javax.swing.GroupLayout(painelDados);
      painelDados.setLayout(painelDadosLayout);
      painelDadosLayout.setHorizontalGroup(
      painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelDadosLayout.createSequentialGroup()
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, painelDadosLayout.createSequentialGroup()
      .addContainerGap()
      .addComponent(painelTabela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(campoCodigo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, painelDadosLayout.createSequentialGroup()
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(rotuloNome)
      .addComponent(jLabel3)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
      .addComponent(campoNome, javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(campoEndereco, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE)))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel4)
      .addComponent(rotuloDoc1)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
      .addComponent(campoDoc1, javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(comboCidade, javax.swing.GroupLayout.Alignment.LEADING, 0, 145, Short.MAX_VALUE)))
      .addGap(18, 18, 18)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(campoCep, javax.swing.GroupLayout.Alignment.TRAILING)
      .addComponent(rotuloDoc2)
      .addComponent(campoDoc2, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addComponent(jLabel5))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(rotuloData)
      .addComponent(campoData, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 862, Short.MAX_VALUE))
      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, painelDadosLayout.createSequentialGroup()
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel11)
      .addComponent(campoEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel6)
      .addComponent(campoTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(18, 18, 18)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jLabel7)
      .addComponent(campoCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(175, 175, 175))
      .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 872, Short.MAX_VALUE)
      .addGroup(javax.swing.GroupLayout.Alignment.LEADING, painelDadosLayout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jLabel2)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(fFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 381, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(comboTipo, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addContainerGap())
      );
      painelDadosLayout.setVerticalGroup(
      painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel1)
      .addGap(6, 6, 6)
      .addComponent(campoCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(6, 6, 6)
      .addComponent(rotuloNome)
      .addGap(1, 1, 1)
      .addComponent(campoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(rotuloDoc1)
      .addGap(6, 6, 6)
      .addComponent(campoDoc1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGap(12, 12, 12)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel3)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(campoEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 9, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(comboCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(rotuloData)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(campoData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(rotuloDoc2)
      .addGap(6, 6, 6)
      .addComponent(campoDoc2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGap(12, 12, 12)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel5)
      .addGap(26, 26, 26))
      .addComponent(campoCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
      .addGap(18, 18, 18)
      .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel11)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(campoEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel6)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(campoTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGroup(painelDadosLayout.createSequentialGroup()
      .addComponent(jLabel7)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(campoCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGap(32, 32, 32)
      .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(22, 22, 22)
      .addGroup(painelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel2)
      .addComponent(fFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(comboTipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(18, 18, 18)
      .addComponent(painelTabela, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap())
      );

      btInicia.setText(“Inicia”);
      btInicia.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btIniciaActionPerformed(evt);
      }
      });

      btNovo.setText(“Novo”);
      btNovo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btNovoActionPerformed(evt);
      }
      });

      btSalvar.setText(“Salvar”);
      btSalvar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btSalvarActionPerformed(evt);
      }
      });

      btExcluir.setText(“Excluir”);
      btExcluir.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btExcluirActionPerformed(evt);
      }
      });

      btAlterar.setText(“Alterar”);
      btAlterar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btAlterarActionPerformed(evt);
      }
      });

      btCancelar.setText(“Cancelar”);
      btCancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btCancelarActionPerformed(evt);
      }
      });

      btSair.setText(“Sair”);
      btSair.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      btSairActionPerformed(evt);
      }
      });

      comboPFPJ.setModel(new javax.swing.DefaultComboBoxModel(new String[] { “Pessoa Física”, “Pessoa Jurídica” }));

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1.setLayout(jPanel1Layout);
      jPanel1Layout.setHorizontalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(painelDados, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addComponent(btNovo)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(btSalvar)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(btExcluir)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(btAlterar)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(btCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
      .addComponent(btSair, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addComponent(comboPFPJ, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(18, 18, 18)
      .addComponent(btInicia)))
      .addContainerGap())
      );
      jPanel1Layout.setVerticalGroup(
      jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jPanel1Layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(btSair)
      .addComponent(btCancelar)
      .addComponent(btAlterar)
      .addComponent(btExcluir)
      .addComponent(btSalvar)
      .addComponent(btNovo))
      .addGap(12, 12, 12)
      .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(btInicia)
      .addComponent(comboPFPJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(painelDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(40, 40, 40))
      );

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addContainerGap())
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 606, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(48, 48, 48))
      );

      pack();
      }//

private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {
comboPFPJ.setEnabled(true);
btInicia.setEnabled(true);
btNovo.setEnabled(false);
btSalvar.setEnabled(false);
btExcluir.setEnabled(false);
btAlterar.setEnabled(false);
btCancelar.setEnabled(true);
btSair.setEnabled(false);

}

private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {
if (validaCampos() == true) {
if (i == 0) {
PessoaFisica pf = new PessoaFisica();
if (campoCodigo.getText().equals("")) {
pf.setId(null);
} else {
pf.setId(Long.parseLong(campoCodigo.getText()));
}
pf.setNome(campoNome.getText());
pf.setEndereco(campoEndereco.getText());
pf.setCpf(campoDoc1.getText());
pf.setRg(campoDoc2.getText());
pf.setEmail(campoEmail.getText());
//pf.setAniversario(campoData.getText()));
pf.setCelular(campoCelular.getText());
pf.setCidade(listaCid.get(comboCidade.getSelectedIndex()));
pf.setTelefone(campoTelefone.getText());
pf.setCep(campoCep.getText());
pfControle.salvar(pf);
limpaCampos();
montaTabela();
validaBotoes(“inicio”);

    } else if (i == 1) {
        PessoaJuridica pj = new PessoaJuridica();
        if (campoCodigo.getText().equals("")) {
            pj.setId(null);
        } else {
            pj.setId(Long.parseLong(campoCodigo.getText()));
        }
        pj.setNome(campoNome.getText());
        pj.setEndereco(campoEndereco.getText());
        pj.setCnpj(campoDoc1.getText());
        pj.setInscricao(campoDoc2.getText());
        pj.setEmail(campoEmail.getText());
        //pj.setConstituicao(campoData.getText()));
        pj.setCelular(campoCelular.getText());
        pj.setCidade(listaCid.get(comboCidade.getSelectedIndex()));
        pj.setTelefone(campoTelefone.getText());
        pj.setCep(campoCep.getText());
        pjControle.salvar(pj);
        limpaCampos();
        montaTabela();
        validaBotoes("inicio");



    }
}

}

private void btExcluirActionPerformed(java.awt.event.ActionEvent evt) {
int a = (JOptionPane.showConfirmDialog(null, “Deseja exluir o registro?”,
“Atenção”, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null));

if (i == 0) {
    if (a == 0) {
        setPf(listaPF.get(tabela.getSelectedRow()));
        pfControle.delete(pf);
        montaTabela();
        validaBotoes("inicio");

    } else if (a == 1) {
        limpaCampos();
        validaBotoes("inicio");
    } else {
        JOptionPane.showMessageDialog(null, "Erro crítico");
        limpaCampos();
        validaBotoes("inicio");

    }
} else if (i == 1) {
    if (a == 0) {
        setPj(listaPJ.get(tabela.getSelectedRow()));
        pjControle.delete(pj);
        montaTabela();
        validaBotoes("inicio");

    } else if (a == 1) {
        limpaCampos();
        validaBotoes("inicio");
    } else {
        JOptionPane.showMessageDialog(null, "Erro crítico");
        limpaCampos();
        validaBotoes("inicio");

    }



}

}

private void btAlterarActionPerformed(java.awt.event.ActionEvent evt) {
//Chamo o ValidaBotões com a ação alterar.
validaBotoes(“alterar”);
}

private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {
limpaCampos();
comboPFPJ.setEnabled(false);
btInicia.setEnabled(false);

validaBotoes("inicio");
// TODO add your handling code here:

}

private void btSairActionPerformed(java.awt.event.ActionEvent evt) {
//Fecha a tela.
System.exit(1);
// TODO add your handling code here:
}

private void btIniciaActionPerformed(java.awt.event.ActionEvent evt) {

if (comboPFPJ.getSelectedIndex() == 0) {
    i = 0;
    painelDados.setVisible(true);
    rotuloData.setText("Aniversário");
    rotuloDoc1.setText("CPF");
    rotuloDoc2.setText("RG");
    validaBotoes("novo");
    montaCombo();
    montaTabela();
    

} else if (comboPFPJ.getSelectedIndex() == 1) {
    i = 1;
    painelDados.setVisible(true);
    rotuloData.setText("Constituição");
    rotuloDoc1.setText("CNPJ");
    rotuloDoc2.setText("Inscrição Estadual");
    rotuloNome.setText("Razão Social");
    validaBotoes("novo");
     montaCombo();
    montaTabela();

}else JOptionPane.showMessageDialog(null, "erro!"+comboPFPJ.getSelectedIndex());

}

public List<PessoaFisica> getListaPF() {
    return listaPF;
}

public void setListaPF(List<PessoaFisica> listaPF) {
    this.listaPF = listaPF;
}

public List<PessoaJuridica> getListaPJ() {
    return listaPJ;
}

public void setListaPJ(List<PessoaJuridica> listaPJ) {
    this.listaPJ = listaPJ;
}

public PessoaFisica getPf() {
    return pf;
}

public void setPf(PessoaFisica pf) {
    this.pf = pf;
}

public PessoaJuridica getPj() {
    return pj;
}

public void setPj(PessoaJuridica pj) {
    this.pj = pj;
}

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            ClienteCad dialog = new ClienteCad(new javax.swing.JFrame(), true);
            dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                public void windowClosing(java.awt.event.WindowEvent e) {
                    System.exit(0);
                }
            });
            dialog.setVisible(true);
        }
    });
}[/code]

ClienteFisicaControle

public class ClienteFisicaControle {

    private DaoGenerico dao;
    private static ClienteFisicaControle instance;

    public ClienteFisicaControle() {
        dao = new DaoHibernateGenerico();
    }

    public static synchronized ClienteFisicaControle getInstance() {
        if (instance == null) {
            instance = new ClienteFisicaControle();
        }
        return instance;
    }

    public void salvar(PessoaFisica obj) {
        //Executa as regras de negócio
        dao.save(obj);
    }

    public List<PessoaFisica> listaTodos() {
        return dao.list(PessoaFisica.class);
    }
 public List<Estado> listaEstados() {
        return dao.list(Estado.class);
    }
    public void delete(PessoaFisica Cid) {
        dao.delete(Cid);
    }

    public List<PessoaFisica> listaFiltrando(String filtro, int tipo) {
        if (tipo == 0) {
            return dao.listCriterio(PessoaFisica.class, "nome", filtro);
        } else {
            return dao.listCriterio(PessoaFisica.class, "estado", filtro);
        }
    }
}

ClienteJuridicaControle

public class ClienteJuridicaControle {

    private DaoGenerico dao;
    private static ClienteJuridicaControle instance;

    public ClienteJuridicaControle() {
        dao = new DaoHibernateGenerico();
    }

    public static synchronized ClienteJuridicaControle getInstance() {
        if (instance == null) {
            instance = new ClienteJuridicaControle();
        }
        return instance;
    }

    public void salvar(PessoaJuridica obj) {
        //Executa as regras de negócio
        dao.save(obj);
    }

    public List<PessoaJuridica> listaTodos() {
        return dao.list(PessoaJuridica.class);
    }
 public List<Estado> listaEstados() {
        return dao.list(Estado.class);
    }
    public void delete(PessoaJuridica Cid) {
        dao.delete(Cid);
    }

    public List<Cidade> listaFiltrando(String filtro, int tipo) {
        if (tipo == 0) {
            return dao.listCriterio(PessoaJuridica.class, "nome", filtro);
        } else {
            return dao.listCriterio(PessoaJuridica.class, "estado", filtro);
        }
    }
}

[color=red]org.hibernate.exception.ConstraintViolationException[/color]: Could not execute JDBC batch update

O hibernate está lançando uma ConstraintViolationException, o que significa que você está tentando inserir um registro com uma chave primária (ou algum atributo unico) já presente na tabela.