Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Entity not recognized as a known entity

 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am writing a JPA code wherein I try to read/write some entities in my database through JPA. One funny thing that I came across was when I am reading an entity for the first time( the entity record is inserted at the backend), JPA throws exception as "Entity name ABC not recognized as a known entity. Perhaps you meant XYZ. Known entity names [XYZ].

Now the difference between ABC and XYZ is that XYZ was inserted through JPA and then read.
When I do the same thing with ABC, it starts recognizing it, which means all the JPA configurations with respect to ABC are correct. Any ideas?
 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone throw some light on this?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you using for your JPA provider? Can you post the full stack trace? Are your entities defined in your persistence XML fully qualified?
 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using EJB3.0. The entities are annotated hence not defined in persistence.xml.

I could not reproduce this exception when I created a new entity at back end and inserted entry to it.
So not sure about the cause...
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec still expects them in the persistence.xml.

You can read this thread

http://stackoverflow.com/questions/1780341/do-i-need-class-elements-in-persistence-xml
or here also
http://docs.oracle.com/cd/E19798-01/821-1841/bnbpy/index.html


Also Hibernate for example has its own @Entity annotation and I have seen people inadvertently use it instead of the one coming out of javax.persistence. Having the wrong import will also cause issues.

 
Prajakta Acharya
Ranch Hand
Posts: 138
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill for your inputs. I will look at the links.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic