1

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:

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?

Community
  • 1
  • 1
angryip
  • 2,140
  • 5
  • 33
  • 67
  • 1
    Similar problem: http://stackoverflow.com/questions/9860181/abstractmethoderror-when-creating-typed-query-with-hibernate-3-6-3-and-jpa-2-0 – Mechkov Oct 14 '16 at 13:09

2 Answers2

4

You have an AbstractMethodError exception which is thrown when an application tries to call an abstract method.
You have quite a mix of Hibernate and JPA versions.

TypedQuery was introduced in JPA 2.0 and Hibernate implements this specification since 3.5.X

Suggesstion : Use implementation from Hibernate version 3.6.3 (or higher).

Rohit Gaikwad
  • 3,677
  • 3
  • 17
  • 40
1

you are probably using two differnet version of interface EntityManager and implementation EntityManagerImpl.

andolsi zied
  • 3,553
  • 2
  • 32
  • 43