-1

I have my spring boot app. in which I have written below code at daoImpl layer.

    @Autowired
    EntityManager


CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<Person> c = qb.createQuery(Person.class);
Root<Person> p = c.from(Person.class);

where "Person" in an @Entity class placed in separate "commons" package.

It's throwing exception "Not an entity.." on second line although it passes the first line. Can someone help me out with the probable causes. This looks something weird to me since the same entity is been accepted on previous line but not on next line.

Meenal
  • 105
  • 3
  • 17
  • 1
    Could you please add more information like Order class and that entire class? – Jonathan JOhx Dec 02 '18 at 06:57
  • By the "first line" you presumably mean calling `createQuery`, but that can take in any old class not just an entity. The "second line" requires an entity. But then you provide insufficient info to decide anything –  Dec 02 '18 at 07:34

2 Answers2

0

Irrespective of you problem generally speaking You can not have a table with name 'Order' because it is a keyword in sql.

Change it to something else and check it will work.

See this if you still want to use any keyword.

Alien
  • 15,141
  • 6
  • 37
  • 57
  • I am sorry, I have given a fake name my actual entity name is based on my project requirement. – Meenal Dec 02 '18 at 07:24
  • But you can have a table called `Order` by quoting the name, and what that has to do with the problem at hand I don't see ... aka this should be a COMMENT not an ANSWER –  Dec 02 '18 at 07:34
  • I have edited my question. Please focus on the error "IllegalArgument Exception: Not an entity....Person" rather than the name I took since I am taking some fake name just for example. – Meenal Dec 02 '18 at 07:55
0

I got the solution for this, we should use @EntityScan instead of @ComponentScan to find the package of entity if it's in separate project.

Meenal
  • 105
  • 3
  • 17