aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA Entity not recognized as a known entity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Entity not recognized as a known entity" Watch "JPA Entity not recognized as a known entity" New topic
Author

JPA Entity not recognized as a known entity

Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

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?


Regards,
Prajakta
Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

Can anyone throw some light on this?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

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?


[How To Ask Questions][Read before you PM me]
Prajakta Acharya
Ranch Hand

Joined: Nov 08, 2012
Posts: 138

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

Joined: Mar 07, 2010
Posts: 1666
    
    7

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

Joined: Nov 08, 2012
Posts: 138

Thanks Bill for your inputs. I will look at the links.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JPA Entity not recognized as a known entity