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

na aula pesquisa 05 . Pesquisas orientado a objetos com JPQL

na aula 05 . Pesquisas orientado a objetos com JPQL do exercicio 7 ta dando esse erro no stack nov 20, 2014 9:03:31 AM org.hibernate.annotations.common.Version INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} nov 20, 2014 9:03:31 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.0.Final} nov 20, 2014 9:03:31 AM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found nov 20, 2014 9:03:31 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist nov 20, 2014 9:03:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) nov 20, 2014 9:03:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 nov 20, 2014 9:03:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: true nov 20, 2014 9:03:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/financas] nov 20, 2014 9:03:32 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {user=root, autocommit=true, release_mode=auto} nov 20, 2014 9:03:32 AM org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure WARN: HHH000342: Could not obtain connection to query metadata : Access denied for user 'root'@'localhost' (using password: NO) nov 20, 2014 9:03:32 AM org.hibernate.dialect.Dialect INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect nov 20, 2014 9:03:32 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation INFO: HHH000422: Disabling contextual LOB creation as connection was null nov 20, 2014 9:03:32 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory nov 20, 2014 9:03:32 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory INFO: HHH000397: Using ASTQueryTranslatorFactory nov 20, 2014 9:03:33 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update nov 20, 2014 9:03:33 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata nov 20, 2014 9:03:33 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute ERROR: HHH000319: Could not get database metadata java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) 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.checkErrorPacket(MysqlIO.java:925) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:834) at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317) at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:204) at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:505) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750) at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:94) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at br.com.caelum.financas.util.JPAUtil.(JPAUtil.java:10) at br.com.caelum.financas.teste.TesteConsulta.main(TesteConsulta.java:12)

nov 20, 2014 9:03:33 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute ERROR: HHH000299: Could not complete schema update java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) 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.checkErrorPacket(MysqlIO.java:925) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301) at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:834) at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317) at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:204) at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:194) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:178) at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:505) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750) at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:94) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at br.com.caelum.financas.util.JPAUtil.(JPAUtil.java:10) at br.com.caelum.financas.teste.TesteConsulta.main(TesteConsulta.java:12)

6 respostas

Provavelmente o usuário root@localhost não tem permissão de acesso ao banco de dados. Verifique se colocou o nome correto do usuário e se colocou a senha correta. Também veja se este usuário tem permissão suficiente.

Verifique se o persistence.xml está dentro da pasta META-INF.

nov 22, 2014 9:18:26 AM org.hibernate.annotations.common.Version INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} nov 22, 2014 9:18:26 AM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.0.Final} nov 22, 2014 9:18:26 AM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found nov 22, 2014 9:18:27 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist nov 22, 2014 9:18:28 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) nov 22, 2014 9:18:28 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 20 nov 22, 2014 9:18:28 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000006: Autocommit mode: true nov 22, 2014 9:18:28 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/financas] nov 22, 2014 9:18:28 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000046: Connection properties: {user=root, password=**, autocommit=true, release_mode=auto} nov 22, 2014 9:18:29 AM org.hibernate.dialect.Dialect INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect nov 22, 2014 9:18:29 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory nov 22, 2014 9:18:29 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory INFO: HHH000397: Using ASTQueryTranslatorFactory nov 22, 2014 9:18:29 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update nov 22, 2014 9:18:29 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata nov 22, 2014 9:18:29 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000261: Table found: financas.conta nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000037: Columns: [numero, banco, id, agencia, titular] nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000108: Foreign keys: [] nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000126: Indexes: [primary] nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000261: Table found: financas.movimentacao nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000037: Columns: [data, tipomovimentacao, conta_id, valor, id, descricao] nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000108: Foreign keys: [fk257eb923c547677d] nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.TableMetadata INFO: HHH000126: Indexes: [fk257eb923c547677d, primary] nov 22, 2014 9:18:30 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete

package br.com.caelum.financas.teste;

import javax.persistence.EntityManager;

import br.com.caelum.financas.modelo.Conta;
import br.com.caelum.financas.modelo.Movimentacao;
import br.com.caelum.financas.util.JPAUtil;

public class TesteMovimentacaoConta {

    /**
     * @param args
     */
    public static void main(String[] args) {
        EntityManager manager = new JPAUtil().getEntityManager();
        Conta conta = manager
                .find(Conta.class, 2);
        manager.close();
        System.out.println(conta.getMovimentacoes.size());

    }

}


package br.com.caelum.financas.modelo;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Conta {

    public static final String getMovimentacoes = null;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String titular;
    private String banco;
    private String agencia;
    private String numero;

    @OneToMany(mappedBy="conta")
    private List<Movimentacao> movimentacoes;
    public Integer getId() {
        return id;
    }

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

    public String getTitular() {
        return titular;
    }

    public void setTitular(String titular) {
        this.titular = titular;
    }

    public String getBanco() {
        return banco;
    }

    public void setBanco(String banco) {
        this.banco = banco;
    }

    public String getAgencia() {
        return agencia;
    }

    public void setAgencia(String agencia) {
        this.agencia = agencia;
    }

    public String getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }
}

stack nov 22, 2014 2:19:43 PM org.hibernate.annotations.common.Version INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} nov 22, 2014 2:19:43 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.2.0.Final} nov 22, 2014 2:19:43 PM org.hibernate.cfg.Environment INFO: HHH000206: hibernate.properties not found nov 22, 2014 2:19:43 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Exception in thread "main" java.lang.ExceptionInInitializerError at br.com.caelum.financas.teste.TesteMovimentacaoConta.main(TesteMovimentacaoConta.java:15) Caused by: javax.persistence.PersistenceException: [PersistenceUnit: financas] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:930) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:72) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at br.com.caelum.financas.util.JPAUtil.(JPAUtil.java:10) ... 1 more Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Conta, for columns: [org.hibernate.mapping.Column(getMovimentacoes)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:314) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:292) at org.hibernate.mapping.Property.isValid(Property.java:239) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:469) at org.hibernate.mapping.RootClass.validate(RootClass.java:270) at org.hibernate.cfg.Configuration.validate(Configuration.java:1284) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1742) at org.hibernate.ejb.EntityManagerFactoryImpl.(EntityManagerFactoryImpl.java:94) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:920) ... 6 more

solução!

Olá Gustavo, tudo bem?

Pelo que parece você não usou nenhum relacionamento no atributo movimentacoes. Você pode postar sua classe conta?

Abraços!

ola Leonardo. postei em baixo da outra classe. mas estou postando de novo @Entity

public class Conta {

    public static final String getMovimentacoes = null;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    private String titular;
    private String banco;
    private String agencia;
    private String numero;

    @OneToMany(mappedBy="conta")
    private List<Movimentacao> movimentacoes;
    public Integer getId() {
        return id;
    }

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

    public String getTitular() {
        return titular;
    }

    public void setTitular(String titular) {
        this.titular = titular;
    }

    public String getBanco() {
        return banco;
    }

    public void setBanco(String banco) {
        this.banco = banco;
    }

    public String getAgencia() {
        return agencia;
    }

    public void setAgencia(String agencia) {
        this.agencia = agencia;
    }

    public String getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }
}