简体   繁体   English

如何在Play Framework 1.2.5中运行JPA查询

[英]How to run a JPA Query in Play Framework 1.2.5

I'm trying to run JPA Query on Play Framework 1.2.5 unsuccessfully. 我试图在Play Framework 1.2.5上运行JPA Query失败。

I tried like this: 我试过这样的:

Query query = JPA.em().createQuery("select * from Book");
List<Book> articles = query.getResultList();
render(articles);

But I get error: 但我得到错误:

The file /app/controllers/Application.java could not be compiled. Error raised is : Query cannot be resolved to a type

What I gotta do? 我要做什么?

You have to import the Query class. 您必须导入Query类。

import javax.persistence.Query;

Doesn't your IDE flag such errors? 你的IDE不会标记这样的错误吗? SHouldn't you be able to fix basic compilation errors before using Play and JPA? 在使用Play和JPA之前,您是否应该能够修复基本的编译错误? Start by learning the basics of Java. 首先学习Java的基础知识。

Also, select * from Book is not JPQL. 另外, select * from Book不是JPQL。 select b from Book b is. select b from Book b是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM