Estava eu fazendo o meu programa no Netbeans com Hibernete e resolvi dar uma “renovada” no programa. Ou seja, comecei
meio que tudo denovo, dando um cntrl c e v e ir limpando um pouco o codigo.
pois bem, nao é que agora o bixo nao funciona?!
O meu .class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package empresa;
import java.io.Serializable;
//import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
//@Entity
public class Empresa implements Serializable {
// @Id
// @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String cnpj;
private String nomeresp;
private String nomeempresa;
private String endereco;
private String numero;
private String complemento;
private String bairro;
private String estado;
private String cep;
private String telfixo;
private String celular;
private String fax;
private String email;
public Empresa() {
}
/**
* Gets the id of this Address.
*
* @return the id
*/
public Long getId() {
return this.id;
}
*
* @param id the new id
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the nomeresp
*/
public String getNomeresp() {
return nomeresp;
}
/**
* @param nomeresp the nomeresp to set
*/
public void setNomeresp(String nomeresp) {
this.nomeresp = nomeresp;
}
/**
* @return the cnpj
*/
public String getCnpj() {
return cnpj;
}
/**
* @param cnpj the cnpj to set
*/
public void setCnpj(String cnpj) {
this.cnpj = cnpj;
}
/**
* @return the nomeempresa
*/
public String getNomeempresa() {
return nomeempresa;
}
/**
* @param nomeempresa the nomeempresa to set
*/
public void setNomeempresa(String nomeempresa) {
this.nomeempresa = nomeempresa;
}
/**
* @return the endereco
*/
public String getEndereco() {
return endereco;
}
/**
* @param endereco the endereco to set
*/
public void setEndereco(String endereco) {
this.endereco = endereco;
}
/**
* @return the numero
*/
public String getNumero() {
return numero;
}
/**
* @param numero the numero to set
*/
public void setNumero(String numero) {
this.numero = numero;
}
/**
* @return the complemento
*/
public String getComplemento() {
return complemento;
}
/**
* @param complemento the complemento to set
*/
public void setComplemento(String complemento) {
this.complemento = complemento;
}
/**
* @return the bairro
*/
public String getBairro() {
return bairro;
}
/**
* @param bairro the bairro to set
*/
public void setBairro(String bairro) {
this.bairro = bairro;
}
/**
* @return the cep
*/
public String getCep() {
return cep;
}
/**
* @param cep the cep to set
*/
public void setCep(String cep) {
this.cep = cep;
}
/**
* @return the estado
*/
public String getEstado() {
return estado;
}
/**
* @param estado the estado to set
*/
public void setEstado(String estado) {
this.estado = estado;
}
/**
* @return the telfixo
*/
public String getTelfixo() {
return telfixo;
}
/**
* @param telfixo the telfixo to set
*/
public void setTelfixo(String telfixo) {
this.telfixo = telfixo;
}
/**
* @return the celular
*/
public String getCelular() {
return celular;
}
/**
* @param celular the celular to set
*/
public void setCelular(String celular) {
this.celular = celular;
}
/**
* @return the fax
*/
public String getFax() {
return fax;
}
/**
* @param fax the fax to set
*/
public void setFax(String fax) {
this.fax = fax;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
}
O meu arquivo aonde ele trabalha com interface grafica:
/*
* Empresa10View.java
*/
package empresa10;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import java.awt.event.ActionEvent;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
/**
* The application's main frame.
*/
public class Empresa10View extends FrameView {
public Empresa10View(SingleFrameApplication app) {
super(app);
initComponents();
private void btt_cadastrolimparActionPerformed(java.awt.event.ActionEvent evt) {
//limpar os campos produtos e pecas
txt_pecamarca.setText("");
txt_pecamodelo.setText("");
txt_pecaserie.setText("");
txt_produtomarca.setText("");
txt_produtomodelo.setText("");
txt_produtoserie.setText("");
}
private void bt_pesquisarcnpjActionPerformed(java.awt.event.ActionEvent evt) {
}
private void bt_ApagarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void bt_limparActionPerformed(java.awt.event.ActionEvent evt) {
//limpar o campo empresa
txt_cnpj.setText("");
txt_nomeempresa.setText("");
txt_nomeresp.setText("");
txt_endereco.setText("");
txt_numero.setText("");
txt_complemento.setText("");
txt_bairro.setText("");
txt_cep.setText("");
txt_telfixo.setText("");
txt_celular.setText("");
txt_fax.setText("");
txt_email.setText("");
}
private void bt_salvarActionPerformed(java.awt.event.ActionEvent evt) {
//salvar tabela empresa
Empresa empresa = new Empresa();
empresa.setCnpj(txt_cnpj.getText());
empresa.setNomeempresa(txt_nomeempresa.getText());
empresa.setNomeresp(txt_nomeresp.getText());
empresa.setEndereco(txt_endereco.getText());
empresa.setNumero(txt_numero.getText());
empresa.setComplemento(txt_complemento.getText());
empresa.setEstado((String) cbb_estado.getSelectedItem());
empresa.setBairro(txt_bairro.getText());
empresa.setCep(txt_cep.getText());
empresa.setTelfixo(txt_telfixo.getText());
empresa.setCelular(txt_celular.getText());
empresa.setFax(txt_fax.getText());
empresa.setEmail(txt_email.getText());
//salvar tabela produtos
Produtos produto = new Produtos();
produto.setProduto(txt_produtoproduto.getText());
produto.setMarca(txt_produtomarca.getText());
produto.setModelo(txt_produtomodelo.getText());
produto.setSerie(txt_produtoserie.getText());
//salvar tabela pecas
Pecas peca = new Pecas();
peca.setPeca(txt_pecapeca.getText());
peca.setMarca(txt_pecamarca.getText());
peca.setModelo(txt_pecamodelo.getText());
peca.setSerie(txt_pecaserie.getText());
EntityManagerFactory emf = Persistence.createEntityManagerFactory(
"Empresa1.0PU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
try {
em.persist(empresa);
em.persist(produto);
em.persist(peca);
em.getTransaction().commit();
} catch (Exception e) {
System.out.println(e.getMessage());
em.getTransaction().rollback();
} finally {
em.close();
}
}
// Variables declaration - do not modify
private javax.swing.JButton bt_Apagar;
private javax.swing.JButton bt_limpar;
private javax.swing.JButton bt_pesquisarcnpj;
private javax.swing.JButton bt_ppeca;
private javax.swing.JButton bt_salvar;
private javax.swing.JButton btt_cadastrolimpar;
private javax.swing.JComboBox cbb_estado;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JPanel jPanel7;
private javax.swing.JPanel jPanel8;
private javax.swing.JPanel jPanel9;
private javax.swing.JLabel lbl_bairro;
private javax.swing.JLabel lbl_celular;
private javax.swing.JLabel lbl_cep;
private javax.swing.JLabel lbl_cnpj;
private javax.swing.JLabel lbl_complemento;
private javax.swing.JLabel lbl_email;
private javax.swing.JLabel lbl_endereco;
private javax.swing.JLabel lbl_estado;
private javax.swing.JLabel lbl_fax;
private javax.swing.JLabel lbl_nomeempresa;
private javax.swing.JLabel lbl_nomeresp;
private javax.swing.JLabel lbl_numero;
private javax.swing.JLabel lbl_pcnpj;
private javax.swing.JLabel lbl_pecamarca;
private javax.swing.JLabel lbl_pecamodelo;
private javax.swing.JLabel lbl_pecapeca;
private javax.swing.JLabel lbl_pecaserie;
private javax.swing.JLabel lbl_pestado;
private javax.swing.JLabel lbl_ppeca;
private javax.swing.JLabel lbl_produtomarca;
private javax.swing.JLabel lbl_produtomodelo;
private javax.swing.JLabel lbl_produtoproduto;
private javax.swing.JLabel lbl_produtoserie;
private javax.swing.JLabel lbl_servico;
private javax.swing.JLabel lbl_telfixo;
private javax.swing.JPanel mainPanel;
private javax.swing.JPanel mainPanel1;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
private javax.swing.JTabbedPane tbb_cadastro;
private javax.swing.JTextField txt_bairro;
private javax.swing.JTextField txt_celular;
private javax.swing.JTextField txt_cep;
private javax.swing.JTextField txt_cnpj;
private javax.swing.JTextField txt_complemento;
private javax.swing.JTextField txt_email;
private javax.swing.JTextField txt_endereco;
private javax.swing.JTextField txt_fax;
private javax.swing.JTextField txt_nomeempresa;
private javax.swing.JTextField txt_nomeresp;
private javax.swing.JTextField txt_numero;
private javax.swing.JTextField txt_pcnpj;
private javax.swing.JTextField txt_pecamarca;
private javax.swing.JTextField txt_pecamodelo;
private javax.swing.JTextField txt_pecapeca;
private javax.swing.JTextField txt_pecaserie;
private javax.swing.JTextField txt_ppeca;
private javax.swing.JTextField txt_produtomarca;
private javax.swing.JTextField txt_produtomodelo;
private javax.swing.JTextField txt_produtoproduto;
private javax.swing.JTextField txt_produtoserie;
private javax.swing.JTextField txt_servico;
private javax.swing.JTextField txt_telfixo;
// End of variables declaration
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
}
Só que agora ta aparecendo esse erro:
run:
25/03/2009 01:37:39 org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.3.1.GA
25/03/2009 01:37:39 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
25/03/2009 01:37:39 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
25/03/2009 01:37:39 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
25/03/2009 01:37:39 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
25/03/2009 01:37:39 org.hibernate.ejb.Version <clinit>
INFO: Hibernate EntityManager 3.3.2.GA
25/03/2009 01:37:40 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
25/03/2009 01:37:40 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
25/03/2009 01:37:40 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
25/03/2009 01:37:40 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: true
25/03/2009 01:37:40 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/postgres
25/03/2009 01:37:40 org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=postgres, password=****, autocommit=true, release_mode=auto}
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: PostgreSQL, version: 8.3.7
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.3 JDBC4 with SSL (build 604)
25/03/2009 01:37:40 org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.PostgreSQLDialect
25/03/2009 01:37:40 org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
25/03/2009 01:37:40 org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
25/03/2009 01:37:40 org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: enabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
25/03/2009 01:37:40 org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
25/03/2009 01:37:40 org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
25/03/2009 01:37:40 org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
25/03/2009 01:37:40 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
25/03/2009 01:37:40 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
25/03/2009 01:37:40 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
25/03/2009 01:37:40 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Unknown entity: empresa10.Empresa
CONSTRUÍDO COM SUCESSO (tempo total: 5 segundos)
Ele fala que nao achou o entity mas todas as classes estao no mesmo grupo…
Obrigado!