jakarta ee java createNamedQuery实体管理器和持久性
我在java中收到这个错误消息
你们有谁知道我该怎么解决这个问题吗
HTTP Status 500 - Filter execution threw an exception
键入Exception report
消息Filter execution threw an exception
说明The server encountered an internal error that prevented it from fulfilling this request.
例外情况
javax.servlet.ServletException: Filter execution threw an exception
root cause
java.lang.Error: Unresolved compilation problem:
The method createNamedQuery(String) in the type EntityManager is not applicable for the arguments (String, Class<User>)
bg.tu_sofia.cinema.dao.UserDAOImpl.getAllUsers(UserDAOImpl.java:22)
bg.tu_sofia.cinema.dao.UserDAOImpl.usernameExists(UserDAOImpl.java:52)
bg.tu_sofia.cinema.filters.UserReconcilerFilter.doFilter(UserReconcilerFilter.java:54)
note The full stack trace of the root cause is available in the SAP logs.
userdoimpl
package bg.tu_sofia.cinema.dao;
import java.util.List;
import javax.persistence.EntityManager;
import bg.tu_sofia.cinema.entities.Cinema;
import bg.tu_sofia.utils.EntityManagerUtils;
public class CinemaDAOImpl implements CinemaDAO {
private EntityManager em;
private EntityManagerUtils dbUtils;
public CinemaDAOImpl() {
this.dbUtils = EntityManagerUtils.getInstance();
this.em = dbUtils.getEntityManagerInstance();
}
public List<Cinema> getAllCinemas() {
return em.createNamedQuery("AllCinemas", Cinema.class).getResultList();
}
public Cinema getCinemaByID(long id) {
return em.find(Cinema.class, id);
}
public void addCinema(Cinema cinema) {
dbUtils.startTransaction(em);
em.persist(cinema);
dbUtils.commitTransaction(em);
}
public void removeCinema(Cinema cinema) {
//TODO : don't forget when removing a cinema to remove all its related screenings.
dbUtils.startTransaction(em);
em.remove(cinema);
dbUtils.commitTransaction(em);
}
public void removeCinemaByID(long removalID) {
removeCinema(getCinemaByID(removalID));
}
}
# 1 楼答案
看起来你调用的方法的参数是它不接受的。如果你给我们看源代码,我们会更有帮助
# 2 楼答案
正在使用的实现似乎是JPA1实现。作为带有此签名的documented方法
是在JPA2.0中引入的。可能的解决办法是:
createNamedQuery(java.lang.String name)
并转换结果李># 3 楼答案
请问“所有电影院”在哪里
一个链接: http://web.securityinnovation.com/appsec-weekly/blog/bid/69739/Use-Named-Queries-with-Java-Persistence-API-JPA
希望这有帮助