Hi,
I've encountered a strange little problem here... When I do the
following locally (in a simple application, not connected to an
Application Server)...
Query query = em.createQuery("select u from LoginUser u where u.login =
:loginname and u.passwd = :pass"); //$NON-NLS-1$
//... setting Parameters...
LoginUser user = null;
try {
user = (LoginUser)query.getSingleResult ();
} catch (NoResultException noResult) {
System.err.println("NoResult");
}
... it works fine, it'll get me the correct "LoginUser" object. But when
I try the same thing in a stateful EJB, the problems start. I'll get the
following error:
<openjpa-1.2.1-r752877:753278 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: An error occurred
while parsing the query filter "select u from LoginUser u where u.login
= :loginname and u.passwd = :pass". Error message: The name "LoginUser"
is not a recognized entity or identifier. Known entity names: []
Funny thing, if I call something like...
LoginUser user = (LoginUser)em.find(LoginUser.class, 1);
...before trying to create the query above, the whole thing will
suddenly work, LoginUser seems to become a recognized Entity (which also
shows, that my classes are correctly enhanced, that the EntityManager
knows them correctly, etc.). It seems, that even though the
EntityManager "knows" the LoginUser Entity (because I can "em.find(...)"
it), it doesn't recognize it in a query.
If I cast the Query to OpenJPAQuery and there set the ResultClass...
if (query instanceof OpenJPAQuery) {
OpenJPAQuery opq = (OpenJPAQuery)query;
opq.setResultClass( LoginUser.class );
}
...it suddenly seems to work. The big question is: Why is this needed?
Is there a setting I can put into the (OpenJPA)EntityManager, that it
will automatically recognize all of its entities in queries? Or do I
really have to cast to OpenJPAQuery everytime I do a query?
Regards,
Michael (The original author Florian did not get a response from the list, after
subscription-verification)