异常NamedQuery的名称JPQL

时间:2016-04-13 14:39:39

标签: java jpa

当我尝试执行此查询时,我遇到了此异常

  

线程中的异常" main" java.lang.IllegalArgumentException异常:   NamedQuery of name:找不到odcalls.call。

这是我的命名查询

 @NamedQuery(name="odcalls.call", 
             query="SELECT C.count(id)," 
                        + "C.date(CalllocalTime)," 
                        + "C.hour(CalllocalTime) from ODCalls as C " 
                  + "where "
                  + " C.date(CallLocalTime) between date_sub(curdate(), Interval 12 month) and date_sub(curdate(),Interval 1 day) : Date " 
                  + " and C.FirstQueue != 0 : String " 
                  + " and C.Calltype in (1) : int " 
                  + "GROUP BY C.hour(CallLocalTime), C.date(CallLocalTime)")

这是我的DAO

     public class ODCallsImpl implements IDao <ODCalls> {
         EntityManager em = EntitiyManagerUtil.getInstance().getEntityManager();
         private List<ODCalls> calls = new ArrayList<ODCalls>();

         @SuppressWarnings("unchecked"  @Override
         @PersistenceContext
         public List<ODCalls> getAll() {
              calls = em.createNamedQuery("odcalls.call",ODCalls.class).getResultList();
              em.close();
              return calls;
         }

1 个答案:

答案 0 :(得分:0)

尝试在您的实体类中声明@NamedQuery

@Entity 
@Table(name="odcalls", schema= "sogedes-db")
@NamedQueries({
    @NamedQuery(name="odcalls.call", 
             query="SELECT C.count(id)," 
                        + "C.date(CalllocalTime)," 
                        + "C.hour(CalllocalTime) from ODCalls as C " 
                  + "where "
                  + " C.date(CallLocalTime) between date_sub(curdate(), Interval 12 month) and date_sub(curdate(),Interval 1 day) : Date " 
                  + " and C.FirstQueue != 0 : String " 
                  + " and C.Calltype in (1) : int " 
                  + "GROUP BY C.hour(CallLocalTime), C.date(CallLocalTime)")
}) 
    public class ODCalls {  
    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name="ID") 
    private String id; 
    @Column(name="CallLocalTime") 
    @Temporal(TemporalType.TIMESTAMP)   
    private Date calllocaltime; 
    @Column(name="CallType") 
    private int calltype;