I'm using Hibernate and JPA for a small project.
Somehow when trying to obtain an typed Query, the
java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerImpl.createQuery(Ljava/lang/String;Ljava/lang/Class;)Ljavax/persistence/TypedQuery
is thrown; org.hibernate.ejb.EntityManagerImpl is from hibernate-entitymanager-3.3.2.GA.jar .
This is not okay throwing the above exception:
public Account read(Account entity) {
EntityManager em = ManagedEntityManagerFactory.getEntityManager();
String jpql = JPQLGenerator.readAccount();
TypedQuery<Account> typedQuery =
em.createQuery(jpql, Account.class);
typedQuery.setParameter("accountId", entity.getAccountId());
return typedQuery.getSingleResult();
}
This is okay, however:
public Account read(Account entity) {
EntityManager em = ManagedEntityManagerFactory.getEntityManager();
String jpql = JPQLGenerator.readAccount();
Query query =
em.createQuery(jpql);
query.setParameter("accountId", entity.getAccountId());
Account account = null;
Object obj = query.getSingleResult();
if(obj instanceof Account) {
account = (Account)obj;
}
return account;
}