Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPA Spring EntityManager这种奇怪行为的解决方案是什么_Java_Spring_Hibernate_Jpa_Maven 3 - Fatal编程技术网

Java JPA Spring EntityManager这种奇怪行为的解决方案是什么

Java JPA Spring EntityManager这种奇怪行为的解决方案是什么,java,spring,hibernate,jpa,maven-3,Java,Spring,Hibernate,Jpa,Maven 3,我正在用JPA、Maven和Hibernate框架下的Spring MVC开发一个webapp,我有以下列表方法: @Transactional public List<Person> list() throws DatabaseException { Person person = new Person("Andrea Patricelli", "a@live.it", "3204524292"); entityManager.persist

我正在用JPA、Maven和Hibernate框架下的Spring MVC开发一个webapp,我有以下列表方法:

@Transactional
    public List<Person> list() throws DatabaseException {
        Person person = new Person("Andrea Patricelli", "a@live.it", "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;
    }
@Transactional
public List()引发DatabaseException{
个人=新人(“安德里亚·帕特里切利”a@live.it", "3204524292");
实体管理者坚持(人);
Person p=entityManager.find(Person.class,“Andrea Patricelli”);
System.out.println(“找到:----------->”+p.getName()+“”+p.getEmail()+“”+p。
getCellPhoneNumber());
Query Query=entityManager.createQuery(“来自个人”);
List resultList=query.getResultList();
System.out.println(“ECCO UN ELEMENTO DELLA LISTA:------>”+resultList.iterator().next().getName());
for(下一个人:结果列表){
System.out.println(“下一个人:+next”);
}
返回结果列表;
}
当我运行我的示例时,我得到了以下堆栈跟踪:

[INFO] [talledLocalContainer] FOUND: -------->Andrea Patricelli andreapatricelli@gmail.com 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
[INFO][talledLocalContainer]找到:------------>Andrea Patricelliandreapatricelli@gmail.com0854312119
【信息】【talledLocalContainer】2013年8月;10:03:10调试o.h.h.i.ast.QueryTranslatorImpl-parse()-HQL:FROM Persons
【信息】【talledLocalContainer】2013年8月;10:03:10调试o.h.h.i.ast.QueryTranslatorImpl---HQL ast---
[INFO][talledLocalContainer]\-[QUERY]节点:“查询”
[INFO][talledLocalContainer]\-[SELECT\u FROM]节点:“SELECT\u FROM”
[INFO][talledLocalContainer]\-[FROM]节点:“FROM”
[INFO][talledLocalContainer]\-[RANGE]节点:“范围”
[INFO][talledLocalContainer]\-[IDENT]节点:“个人”
[信息][talledLocalContainer]
【信息】【talledLocalContainer】2013年8月;10:03:10调试o.h.hql.internal.ast.ErrorCounter-throwQueryException():无错误

【信息】【talledLocalContainer】2013年8月;10:03:11调试o.h.h.i.antlr.HqlSqlBaseWalker-选择此行给出了以下问题:

Query query = entityManager.createQuery("FROM Persons");
由于实体类的名称为
Person
,并且您在查询中给定了
Persons
,因此其行为异常

Query query = entityManager.createQuery("FROM Person"); // This should fetch everything now, as expected!

这一行给出了以下问题:

Query query = entityManager.createQuery("FROM Persons");
由于实体类的名称为
Person
,并且您在查询中给定了
Persons
,因此其行为异常

Query query = entityManager.createQuery("FROM Person"); // This should fetch everything now, as expected!

ECCO UN ELEMENTO NELLA LISTA是我引用元素的详细模式,不重要ECCO UN ELEMENTO NELLA LISTA是我引用元素的详细模式,不重要非常感谢,我在创建数据库表Person intead of Object Person时出错了!非常感谢,我在创建数据库表Persons interad的对象Person时出错了!