简体   繁体   中英

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.

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.

import javax.persistence.Query;

Doesn't your IDE flag such errors? SHouldn't you be able to fix basic compilation errors before using Play and JPA? Start by learning the basics of Java.

Also, select * from Book is not JPQL. select b from Book b is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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