0

I have a weird problem with my Java code.

I am facing the following exception:

java.lang.IllegalArgumentException: Not an entity: class

Note that I have a persistence.xml where my entites are listed. My entites have @Entity annotation.

When I do:

final Query q = entityManager.createQuery("from " + className + " c");  
q.getResultList().iterator(); 

it returns me results.

But when I do:

// pType is Class<T> 
final TypedQuery<T> queryAll = entityManager.createQuery(query.select(query.from(pType))); 
return queryAll.getResultList(); 

it returns me the Exception above.

Do you have an idea?

Alex Shesterov
  • 26,085
  • 12
  • 82
  • 103
Hejk
  • 185
  • 3
  • 18
  • What is `pType`? Is it a string that contains something like `MyClassName.class`? Make sure that the `.class` isn't in there. – Jesper Mar 23 '18 at 09:46
  • As I mentioned in my snippet, "pType is Class type" – Hejk Mar 23 '18 at 09:49

3 Answers3

0

I've had a error similar your, in my persistence.xml, but I didn't add a class entity, check if your problem is this. Example in persistence.xml

<persistence-unit name="PERSISTENCE" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <class>CLASSE_ENTITY</class>
</persistence-unit>
0

This issue may occur when given class has not been added to Hibernate configuration.

One of the way to add it using

new org.hibernate.cfg.Configuration()
      .addProperties(properties)
      .addAnnotatedClass(MyEntity.class)
Sourabh
  • 1,515
  • 1
  • 14
  • 21
0

check your Hibernate and Spring versions to be compatible. I had the same issue, I had changed the Hibernate and Spring versions, the problem has gone.

Issa Khodadadi
  • 917
  • 7
  • 19