Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA: Entities not binding/mapping when placed in package two levels deep

843833Apr 25 2010 — edited Apr 25 2010
I am learning to develop with JPA for the first time and built a simple log-in web application using JBoss AS and JavaDB and came across a curious problem. Please read on so I can describe the problem accurately...

When my code tried to query a value from the database table "ADMINISTRATOR" (using JPA query) it always resulted in an exception:
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Administrator is not mapped
I researched this exception and found this usually happens when the query incorrectly refers to the database table instead of the class, or when the entity is not annotated correctly because of misspelling. However, I quadruple checked and this was definitely not the case.

After lengthy trial and error I noticed that when my application was deployed the container logs were not showing certain event logs when compared to deploying a different, working application, i.e. the working application showed
INFO  [AnnotationBinder] ... Binding entity from annotated class: business.Event
INFO  [EntityBinder] ... Bind entity business.Event on table EVENT
but my application did not generate these kinds of events.

So apparently the problem was that the entities were not binding correctly to the tables for some reason.

My entities were contained in a package business.entities. On a hunch I tried moving all of my entities out of the current package and up one level into the business package. After doing this and redeploying I found that the container was now logging events as above.

Now (apart from the fact that I have got a new exception to deal with!) it appears that moving the entities into a higher level package solved the entity mapping problem.

But why were the entities not binding/mapping when they were in a package two levels deep, but were binding/mapping when I moved to a package one level deep?

I can't see a logical reason for this. Is a bug? A limitation of either JPA, or the JBoss implementation of the API, perhaps? Or am I missing something obvious?

I am hoping someone with more experience in the JPA can offer some insight to this, and if it is a bug I can bring the issue to whoever is responsible.

Many thanks for your help.

Regards.
Mark
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 23 2010
Added on Apr 25 2010
0 comments
381 views