EntityManagerFactory entityManagerFactory = Persistence
.createEntityManagerFactory("PrimeEclipseLink");
EntityManager entityManager = entityManagerFactory
.createEntityManager();
Query query=entityManager.createQuery("select name from member");
List<String> memberList=query.getResultList();
for(String e:memberList){
System.out.println(e);
我想在我的数据库中列出名称,但是我收到这样的错误消息。
Tem 14, 2015 9:55:28 AM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: #{memberControl.login()}: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [select name from member].
[23, 23] An identification variable must be provided for a range variable declaration.
javax.faces.FacesException: #{memberControl.login()}: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [select name from member].
[23, 23] An identification variable must be provided for a range variable declaration.
答案 0 :(得分:2)
尝试在以下内容中使用createNativeQuery
代替createQuery
:
Query query=entityManager.createNativeQuery("select name from member");
答案 1 :(得分:2)
消息显示您的JPQL查询无效。只需将您的JPQL查询更改为
即可SELECT m.name FROM member m
然后它会工作(因为这是有效的JPQL)。 另一个答案意味着你抛弃数据存储独立性。