Hibernate Erro

10 respostas
SirDominque

Gente, estou aprendendo a usar hibernate, e deu esse erro aqui :

run:

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.annotations.Version 

Informações: Hibernate Annotations <a href="http://3.3.1.GA">3.3.1.GA</a>

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.Environment 

Informações: Hibernate 3.2.5

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.Environment 

Informações: hibernate.properties not found

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.Environment buildBytecodeProvider

Informações: Bytecode provider name : cglib

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.Environment 

Informações: using JDK 1.4 java.sql.Timestamp handling

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.Configuration configure

Informações: configuring from resource: /hibernate.cfg.xml

Mar 20, 2012 10:51:09 AM org.hibernate.cfg.Configuration getConfigurationInputStream

Informações: Configuration resource: /hibernate.cfg.xml

Exception in thread “main” java.lang.ExceptionInInitializerError

at aprendendohibernate.Teste.main(Teste.java:17)

Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found

at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)

at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)

at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:972)

at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:69)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)

at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:966)

at aprendendohibernate.HibernateUtil.(HibernateUtil.java:14)

… 1 more

Java Result: 1

CONSTRUÍDO COM SUCESSO (tempo total: 1 segundo)

estou seguindo este tutorial :
http://javafree.uol.com.br/artigo/874971/Acessando-Dados-com-Java-Parte-3-Hibernate-Annotations.html

mas eu nao fiz este passo :

““O próximo passo é configurar nossa fonte de dados. Nesse ponto usamos mapeamento XML, o único. Nos iremos adicionar os dados da fonte e as classes mapeadas. Observe bem os parâmetros da fonte de dados, essa parte é muito comum apresentar erros. Meu XML ficou assim:””"

Como que eu crio esse arquivo p/ configurar a fonte de dados??? Como que eu crio Esse XML ? Como eu Soluciono este erro?

Aguardo resposta

Obrigado pela ajuda!

10 Respostas

romarcio

Ele não está encontrando o arquivo hibernate.cfg.xml
Este arquivo deve ficar dentro do diretório “src” e não dentro dos pacotes que contém o código fonte.

Qualquer coisa, da uma olhada aqui: utilizando-swing-com-hibernate-sessionfactory

SirDominque

como assim pasta SRC? Aqui eu só tenho META-INF

Segue foto de como esta no meu netbeans :

http://imageshack.us/photo/my-images/24/hibernateerro.jpg/

Valeu pela respostaXD

Aguardo ajuda!!!

romarcio

Andre Lopes:
como assim pasta SRC? Aqui eu só tenho META-INF

Segue foto de como esta no meu netbeans :

http://imageshack.us/photo/my-images/24/hibernateerro.jpg/

Valeu pela respostaXD

Aguardo ajuda!!!

No netbeans o src seria o mesmo que “pacotes de código fonte”. Se você for no diretório do seu projeto e abrir as pastas, vai ver que esse pacote na verdade é “src”.

SirDominque

Ahh ok!

Como eu arrumo isto então? Eu tenho que criar o XML no bloco de notas e colocar na pasta?

romarcio

Andre Lopes:
Ahh ok!

Como eu arrumo isto então? Eu tenho que criar o XML no bloco de notas e colocar na pasta?

Pode ser, ou cria direto pelo netbeans. Clica com o botão direito do mouse em “pacotes de código fonte” e procura por criar arquivo xml, ou algo do tipo. Ou então criar no bloco de notas e cola la dentro.

SirDominque

Ok, Agora deu outro erro :

http://imageshack.us/photo/my-images/440/hibernateerro2.jpg/

Acho que o erro está aqui :


o que eu coloco aí ?

romarcio

Você deve declarar o pacote e a classe que contém os mapeamentos do hibernate:

&lt;mapping class="aprendendohibernate.AprendendoJava"/&gt;
&lt;mapping class="aprendendohibernate.Cadastro"/&gt;
&lt;mapping class="aprendendohibernate.Estoque"/&gt;

Mas só coloque ali as classes que contém os mapeamentos, ou seja, as anotações.

SirDominque

Deu CERTO!!!

A row esta dentro da tabela, mas deu essa mensagem, é normal :

run: Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.Version <clinit> Informações: Hibernate Annotations 3.3.1.GA Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Environment <clinit> Informações: Hibernate 3.2.5 Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Environment <clinit> Informações: hibernate.properties not found Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Environment buildBytecodeProvider Informações: Bytecode provider name : cglib Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Environment <clinit> Informações: using JDK 1.4 java.sql.Timestamp handling Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Configuration configure Informações: configuring from resource: /hibernate.cfg.xml Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Configuration getConfigurationInputStream Informações: Configuration resource: /hibernate.cfg.xml Mar 20, 2012 11:36:27 AM org.hibernate.cfg.Configuration doConfigure Informações: Configured SessionFactory: null Mar 20, 2012 11:36:27 AM org.hibernate.cfg.AnnotationBinder bindClass Informações: Binding entity from annotated class: aprendendohibernate.Cadastro Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Cadastro.findAll => SELECT c FROM Cadastro c Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Cadastro.findByIdcadastro => SELECT c FROM Cadastro c WHERE c.idcadastro = :idcadastro Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Cadastro.findByNome => SELECT c FROM Cadastro c WHERE c.nome = :nome Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Cadastro.findByIdade => SELECT c FROM Cadastro c WHERE c.idade = :idade Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.EntityBinder bindTable Informações: Bind entity aprendendohibernate.Cadastro on table cadastro Mar 20, 2012 11:36:27 AM org.hibernate.cfg.AnnotationBinder bindClass Informações: Binding entity from annotated class: aprendendohibernate.Estoque Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findAll => SELECT e FROM Estoque e Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByIdestoque => SELECT e FROM Estoque e WHERE e.idestoque = :idestoque Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByNSerie => SELECT e FROM Estoque e WHERE e.nSerie = :nSerie Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByMarca => SELECT e FROM Estoque e WHERE e.marca = :marca Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByCor => SELECT e FROM Estoque e WHERE e.cor = :cor Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByTamanho => SELECT e FROM Estoque e WHERE e.tamanho = :tamanho Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByNome => SELECT e FROM Estoque e WHERE e.nome = :nome Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.QueryBinder bindQuery Informações: Binding Named query: Estoque.findByObs => SELECT e FROM Estoque e WHERE e.obs = :obs Mar 20, 2012 11:36:27 AM org.hibernate.cfg.annotations.EntityBinder bindTable Informações: Bind entity aprendendohibernate.Estoque on table estoque Mar 20, 2012 11:36:27 AM org.hibernate.cfg.AnnotationConfiguration secondPassCompile Informações: Hibernate Validator not found: ignoring Mar 20, 2012 11:36:27 AM org.hibernate.connection.DriverManagerConnectionProvider configure Informações: Using Hibernate built-in connection pool (not for production use!) Mar 20, 2012 11:36:27 AM org.hibernate.connection.DriverManagerConnectionProvider configure Informações: Hibernate connection pool size: 1 Mar 20, 2012 11:36:27 AM org.hibernate.connection.DriverManagerConnectionProvider configure Informações: autocommit mode: false Mar 20, 2012 11:36:27 AM org.hibernate.connection.DriverManagerConnectionProvider configure Informações: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/estoque Mar 20, 2012 11:36:27 AM org.hibernate.connection.DriverManagerConnectionProvider configure Informações: connection properties: {user=root, password=****} Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: RDBMS: MySQL, version: 5.5.21 Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.13 ( Revision: ${bzr.revision-id} ) Mar 20, 2012 11:36:27 AM org.hibernate.dialect.Dialect <init> Informações: Using dialect: org.hibernate.dialect.MySQLDialect Mar 20, 2012 11:36:27 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory Informações: Using default transaction strategy (direct JDBC transactions) Mar 20, 2012 11:36:27 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup Informações: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Automatic flush during beforeCompletion(): disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Automatic session close at end of transaction: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: JDBC batch size: 15 Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: JDBC batch updates for versioned data: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Scrollable result sets: enabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: JDBC3 getGeneratedKeys(): enabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Connection release mode: auto Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Maximum outer join fetch depth: 2 Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Default batch fetch size: 1 Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Generate SQL with comments: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Order SQL updates by primary key: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Order SQL inserts for batching: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory Informações: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory Mar 20, 2012 11:36:27 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init> Informações: Using ASTQueryTranslatorFactory Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Query language substitutions: {} Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: JPA-QL strict compliance: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Second-level cache: enabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Query cache: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory createCacheProvider Informações: Cache provider: org.hibernate.cache.NoCacheProvider Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Optimize cache for minimal puts: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Structured second-level cache entries: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Echoing all SQL to stdout Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Statistics: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Deleted entity synthetic identifier rollback: disabled Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Default entity-mode: pojo Mar 20, 2012 11:36:27 AM org.hibernate.cfg.SettingsFactory buildSettings Informações: Named query checking : enabled Mar 20, 2012 11:36:27 AM org.hibernate.impl.SessionFactoryImpl <init> Informações: building session factory Mar 20, 2012 11:36:27 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance Informações: Not binding factory to JNDI, no JNDI name configured Hibernate: insert into cadastro (Idade, Nome, idcadastro) values (?, ?, ?) CONSTRUÍDO COM SUCESSO (tempo total: 1 segundo)

romarcio

Sim, esse é o Log de execução do Hibernate.

Diguinho.Max

esse log é norml amigo quanto tem o INFO: é um aviso do que está acontecendo no servidor, deve se preocupar com logs de ERRO =)

Criado 20 de março de 2012
Ultima resposta 27 de mar. de 2012
Respostas 10
Participantes 3