Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

AULA 2 - Exercio Caelum com erro.

Ao fazer o exercicio da aula 2 do curso JPA, é apresentado o segunte erro: Out 05, 2013 11:49:57 AM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} Out 05, 2013 11:49:57 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.0.Final} Out 05, 2013 11:49:57 AM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Out 05, 2013 11:49:57 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Out 05, 2013 11:49:57 AM org.hibernate.ejb.Ejb3Configuration configure INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named financas at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at br.com.caelum.financas.teste.TesteJPA.main(TesteJPA.java:21) Não entendi o porque desse erro, já que o código está igual ao apresentado no curso. Podem me ajudar ?

4 respostas

Oi Thiago,

Repare a mensagem "Could not find any META-INF/persistence.xml".

O JPA/Hibernate não encontrou o persistence.xml e consequentemente gerou uma exceção.

O arquivo persistence.xml deve estar dentro da pasta META-INF do seu classpath (no Eclipse dentro da pasta src).

Abraços

Realizei a alteração. Ao rodar o projeto, verifico no mysql que a tabela foi criada. Entretanto, não existe nenhum dado contido na tabela. O código gerado na saída do eclipse é:Out 05, 2013 12:20:45 PM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} Out 05, 2013 12:20:45 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.0.Final} Out 05, 2013 12:20:45 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Out 05, 2013 12:20:45 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Out 05, 2013 12:20:46 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) Out 05, 2013 12:20:47 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 Out 05, 2013 12:20:47 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: true Out 05, 2013 12:20:47 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/financas] Out 05, 2013 12:20:47 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {user=root, password=****, autocommit=true, release_mode=auto} Out 05, 2013 12:20:47 PM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect Out 05, 2013 12:20:47 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory Out 05, 2013 12:20:47 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory Out 05, 2013 12:20:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update Out 05, 2013 12:20:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata Out 05, 2013 12:20:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema Out 05, 2013 12:20:48 PM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: Conta Out 05, 2013 12:20:48 PM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata INFO: HHH000262: Table not found: Conta Out 05, 2013 12:20:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete Hibernate: insert into Conta (agencia, banco, numero, titular) values (?, ?, ?, ?) Out 05, 2013 12:20:48 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions WARN: SQL Error: 0, SQLState: S1000 Out 05, 2013 12:20:48 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: Could not retrieve transation read-only status server Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881) at br.com.caelum.financas.teste.TesteJPA.main(TesteJPA.java:26) Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136) at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96) at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2966) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3477) at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203) at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183) at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167) at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321) at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286) at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192) at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125) at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78) at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151) at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78) at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:852) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:826) at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:830) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875) ... 1 more Caused by: java.sql.SQLException: Could not retrieve transation read-only status server at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:951) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:941) at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3936) at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3907) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2408) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133) ... 22 more Caused by: java.sql.SQLException: Unknown system variable 'tx_read_only' at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2809) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2758) at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612) at com.mysql.jdbc.ConnectionImpl.isReadOnly(ConnectionImpl.java:3930) ... 27 more Alguém pode me auxiliar?

Detalhe: Utilizo o Mysql versão 6

solução!

Oi Thiago, como falei no outro post, para usar MySql 6 você precisa atualizar o driver JDBC. Eu não encontrei esse JAR como download e aconselho usar MySQL 5.

Abraços