dúvida nub.. primeiro teste de persistencia com hibernate/mysql

olá pessoal.

to tentando seguir o tutorial: http://www.k19.com.br/artigos/configurando-hibernate-com-mysql/

pra fazer minha primeira persistencia com hibernate mas infelizmente consegui o seguinte erro. e não intendi oque pode ser…

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named test
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
	at UnitTest.TesteInsereProduto.main(TesteInsereProduto.java:13)

nesse arquivo xml só houve 2 modificações…

  • senha do db
  • e o próprio DB
    persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	xmlns="http://java.sun.com/xml/ns/persistence">
	<persistence-unit name="test">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<class>entities.Produto</class>
		<properties>
			<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
			<property name="hibernate.hbm2ddl.auto" value="update" />
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
			<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
			<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/test" />
			<property name="javax.persistence.jdbc.user" value="root" />
			<property name="javax.persistence.jdbc.password" value="root" />
		</properties>
	</persistence-unit>
</persistence>

estou desconfiado que está faltando alguma lib mas não tenho certeza… usei somente a de conexão com mysql e as “required” do hibernate…

desde já muito obrigado

EDITADO

bom pessoal eu add todas as libs do hibernate como teste e arrumei um pequeno erro no xml persistence.xml q está acima… agora veio um erro monstruoso…

Jan 25, 2013 6:01:52 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Jan 25, 2013 6:01:52 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.9.Final}
Jan 25, 2013 6:01:52 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Jan 25, 2013 6:01:52 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: test] class or package not found
	at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1401)
	at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1184)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1048)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:291)
	at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:373)
	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
	at UnitTest.TesteInsereProduto.main(TesteInsereProduto.java:13)
Caused by: java.lang.ClassNotFoundException: entities.Produto
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:170)
	at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1318)
	at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1390)
	... 8 more

mais uma vez obrigado

Troque onde você está passando test e coloca lojavirtualDB

Fiz a alteração proposta e estou recebendo o mesmo erro monstruoso citado no edit anterior.

sim o DB lojavirtualDB foi criando antes do teste, mas a tabela Produto eu deixei por conta do hibernate…

obrigado pela resposta @Hebert Coelho

[quote=ericrf]Fiz a alteração proposta e estou recebendo o mesmo erro monstruoso citado no edit anterior.

sim o DB lojavirtualDB foi criando antes do teste, mas a tabela Produto eu deixei por conta do hibernate…

obrigado pela resposta @Hebert Coelho
[/quote]Evite fazer edits, fica mais fácil de ver a evolução do tópico se você for postando a solução abaixo. [=

[quote]Caused by: java.lang.ClassNotFoundException: entities.Produto [/quote]Esse é seu erro. Essa classe está nesse pacote mesmo? Está com exatamente esse nome?

realmente o pacote estava errado.

a persistencia foi feita…
Mesmo assim obetive erros no console.

Jan 25, 2013 6:12:13 PM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
Jan 25, 2013 6:12:13 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.9.Final}
Jan 25, 2013 6:12:13 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
Jan 25, 2013 6:12:13 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jan 25, 2013 6:12:14 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jan 25, 2013 6:12:14 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 5
Jan 25, 2013 6:12:14 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
Jan 25, 2013 6:12:14 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/lojavirtualDB]
Jan 25, 2013 6:12:14 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto}
Jan 25, 2013 6:12:14 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jan 25, 2013 6:12:14 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
Jan 25, 2013 6:12:14 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Jan 25, 2013 6:12:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
Jan 25, 2013 6:12:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
Jan 25, 2013 6:12:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
Jan 25, 2013 6:12:14 PM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: Produto
Jan 25, 2013 6:12:14 PM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: HHH000262: Table not found: Produto
Jan 25, 2013 6:12:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Hibernate: 
    insert 
    into
        Produto
        (nome, preco) 
    values
        (?, ?)

isso é normal?

tirei uma print com as libs:
http://s7.postimage.org/7tq3dgtkr/hibernate_libs.png

O hibernate não encontrou sua classe entites.Produto este realmente é o caminho completo para a sua classe, acho também que esta faltando algum .jar eu seguir este mesmo tutorial pois sou iniciante em java e tive alguns problemas com as lib’s.

Quando for erro de funcionamento você verá escrito ou WARN ou ERROR, mas em geral não está com INFO.

Olhe a sequencia de mensagens:
INFO: HHH000102: Fetching database metadata
INFO: HHH000396: Updating schema
INFO: HHH000262: Table not found: Produto
INFO: HHH000232: Schema update complete

Ele começou a olhar o banco de dados, sincronizou o schema, procurou e não encontrou a tabela e finalmente criou o que faltava. [=

A tá… é que apareceu um monte de coisa vermelha e na minha cabeça o vermelho era erro de agora em diante vou tentar ler mais as mensagens de saída do console
isso ae…

Muito obrigado @Hebert Coelho @Cleidiano

resolvido