简体   繁体   English

createQuery期间的java.lang.AbstractMethodError

[英]java.lang.AbstractMethodError during createQuery

I am attempting to retrieve a list of results from my database, by following an example in this answer. 我试图通过以下答案中的示例从我的数据库中检索结果列表 Howeverm, I keep getting the following error: 但是,我一直收到以下错误:

java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerImpl.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery;

Here is my code, to denote how I am calling this: 这是我的代码,表示我如何调用它:

@Entity
@Table(name = "MY_TABLE")
public class CoolsEntity implements Serializable {

    @Id
    @Column(name = "ID", columnDefinition = "Decimal(10,0)")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private String id;

    @Column(name = "COOL_GUY_NAME")
    private String name;

    public String getId() {
        return id;
    }

    public void setId(final String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name= name;
    }
}

This code below generates the error: 以下代码生成错误:

final String sql = "select c from CoolsEntity c";
final TypedQuery<CoolsEntity> query = em.createQuery(sql, CoolsEntity.class);
final List<CoolsEntity> results = query.getResultList();
return results;

However, if I do something like this, I can see the results: 但是,如果我这样做,我可以看到结果:

final String sql = "select c from CoolsEntity c";
final Query query = em.createQuery(sql);
@SuppressWarnings("unchecked")
final List<CoolsEntity> results = query.getResultList();
return results;

All of the references to em are imported through this package: 所有对em的引用都是通过此包导入的:

import javax.persistence.EntityManager

Shouldn't the two queries above generate the same result? 以上两个查询不应该生成相同的结果吗? Am I missing a cast to the List interface to allow this to work in the typed query? 我是否错过了对List接口的强制转换以允许它在类型化查询中工作?

You have an AbstractMethodError exception which is thrown when an application tries to call an abstract method. 您有一个AbstractMethodError异常,当应用程序尝试调用抽象方法时会抛出该异常。
You have quite a mix of Hibernate and JPA versions. 你有很多Hibernate和JPA版本。

TypedQuery was introduced in JPA 2.0 and Hibernate implements this specification since 3.5.X TypedQuery是在JPA 2.0中引入的,Hibernate自3.5.X起实现了这个规范

Suggesstion : Use implementation from Hibernate version 3.6.3 (or higher). 建议:使用Hibernate 3.6.3版(或更高版本)的实现。

您可能正在使用两个不同版本的接口EntityManager和实现EntityManagerImpl

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

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