1
我正在开发使用JPA,Maven和Hibernate框架下Spring MVC的web应用程序,我有这个名单的方法:什么是解决JPA春的这种奇怪的行为的EntityManager
@Transactional
public List<Person> list() throws DatabaseException {
Person person = new Person("Andrea Patricelli", "[email protected]", "3204524292");
entityManager.persist(person);
Person p = entityManager.find(Person.class, "Andrea Patricelli");
System.out.println(" FOUND: -------->" + p.getName() + " " + p.getEmail() + " " + p.
getCellPhoneNumber());
Query query = entityManager.createQuery("FROM Persons");
List<Person> resultList = query.getResultList();
System.out.println("ECCO UN ELEMENTO DELLA LISTA: ------->" + resultList.iterator().next().getName());
for (Person next : resultList) {
System.out.println("next person: " + next);
}
return resultList;
}
当我运行我的例子我得到这个堆栈跟踪:
[INFO] [talledLocalContainer] FOUND: -------->Andrea Patricelli [email protected] 0854312119
[INFO] [talledLocalContainer] 08 mag 2013;10:03:10 DEBUG o.h.h.i.ast.QueryTranslatorImpl - parse() - HQL: FROM Persons
[INFO] [talledLocalContainer] 08 mag 2013;10:03:10 DEBUG o.h.h.i.ast.QueryTranslatorImpl - --- HQL AST ---
[INFO] [talledLocalContainer] \-[QUERY] Node: 'query'
[INFO] [talledLocalContainer] \-[SELECT_FROM] Node: 'SELECT_FROM'
[INFO] [talledLocalContainer] \-[FROM] Node: 'FROM'
[INFO] [talledLocalContainer] \-[RANGE] Node: 'RANGE'
[INFO] [talledLocalContainer] \-[IDENT] Node: 'Persons'
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] 08 mag 2013;10:03:10 DEBUG o.h.hql.internal.ast.ErrorCounter - throwQueryException() : no errors
[INFO] [talledLocalContainer] 08 mag 2013;10:03:11 DEBUG o.h.h.i.antlr.HqlSqlBaseWalker - select << begin [level=1, statement=select]
[INFO] [talledLocalContainer] 08 mag 2013;10:03:11 DEBUG o.h.e.t.spi.AbstractTransactionImpl - rolling back
[INFO] [talledLocalContainer] 08 mag 2013;10:03:11 DEBUG o.h.e.t.i.jdbc.JdbcTransaction - rolled JDBC Connection
[INFO] [talledLocalContainer] 08 mag 2013;10:03:11 DEBUG o.h.e.t.i.jdbc.JdbcTransaction - re-enabling autocommit
[INFO] [talledLocalContainer] 08 mag 2013;10:03:11 DEBUG o.h.e.j.i.LogicalConnectionImpl - Releasing JDBC connection
[INFO] [talledLocalContainer] 08 mag 2013;10:03:11 DEBUG o.h.e.j.i.LogicalConnectionImpl - Released JDBC connection
,我会想到这个代码打印所有的人的名单在我的数据库(3人),这似乎是在查询未格式化好,有一个错误,但我没有错误!或在另一方面我做了一个错误的理解如何进行查询与Hibernate ...
ECCO联合国ELEMENTO内拉LISTA是我详细模式是指元件,并不重要 – andPat 2013-05-08 08:10:58