O meu exercício está aparecendo na console o erro. O id 1 existe no banco.
Alguém pode me ajudar?
CONSOLE:
abr 20, 2016 12:20:02 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: JPA_UTIL
...]
abr 20, 2016 12:20:02 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.1.0.Final}
abr 20, 2016 12:20:02 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
abr 20, 2016 12:20:02 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
abr 20, 2016 12:20:02 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
abr 20, 2016 12:20:02 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
abr 20, 2016 12:20:02 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/financas]
abr 20, 2016 12:20:02 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
abr 20, 2016 12:20:02 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
abr 20, 2016 12:20:02 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
abr 20, 2016 12:20:03 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
abr 20, 2016 12:20:03 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
abr 20, 2016 12:20:04 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
TESTECONSULTA:
package br.com.alura.teste;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import br.com.alura.modelo.Conta;
import br.com.alura.modelo.Movimentacao;
import br.com.alura.util.JPAUtil;
public class TesteConsulta {
public static void main(String[] args) {
EntityManager manager = new JPAUtil().getEntityManager();
manager.getTransaction().begin();
Conta conta = new Conta();
conta.setId(1);
// Positional Parameter Notation
// Query query = manager.createQuery("select m from Movimentacao m where m.conta = ?1");
// query.setParameter(1, conta);
// Named Parameter Notation
Query query = manager.createQuery("select m from Movimentacao m where m.conta = :pConta");
query.setParameter("pConta", conta);
List<Movimentacao> movimentacoes = query.getResultList();
for (Movimentacao m : movimentacoes) {
System.out.println("DESCRIÇÃO....... "+ m.getDescricao());
System.out.println("VALOR ........R$ "+ m.getValor());
}
manager.getTransaction().commit();
manager.close();
}
}