0

我在 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.

用户DOAImpl

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));
    }

}
4

3 回答 3

5

Implementation in use seems to be JPA 1 implementation. As documented Method with this signature

TypedQuery createNamedQuery(String name, Class resultClass)

was introduced in JPA 2.0. Possible solutions are:

  1. upgrading to JPA 2.0 implementation or
  2. using createNamedQuery(java.lang.String name) instead and casting result.
于 2013-07-15T20:50:52.580 回答
0

NamedQuery“AllCinemas”在哪里?

一个链接: http ://web.securityinnovation.com/appsec-weekly/blog/bid/69739/Use-Named-Queries-with-Java-Persistence-API-JPA

希望这可以帮助

于 2013-06-29T21:39:38.603 回答
0

看起来您正在调用一个带有它不接受的参数的方法。如果您向我们展示源代码,我们会更有帮助。

于 2013-06-29T21:09:44.247 回答