What about called getNamedQuery, or whatever the actual method name is on EntityManager, and if it returns null, then you know it doesn't exist.
You should be able to get the Configuration object from the EntityManagerFactory, although again, I am not positive that that method is in JPA, I am too used to Hibernate's classes, and haven't gotten the time to memorize the apis. Sorry.
Originally posted by avihai marchiano: the exception cause to rollback. what i did is un ugly trick i get in reflection (private field )this field from seesionfactoryimpl
I was actually thinking about your issue today while Snowboarding. I was just finding it odd that your might ever be passing a String for a named query that doesn't exist. Like a user types in a name in some UI and it is just passed.
Anyway, Looking at the Javadoc for Configuration, and why you can't get to it, is
"The Configuration is meant only as an initialization-time object. SessionFactorys are immutable and do not retain any association back to the Configuration."
So it actually no longer exists as a Configuration object after it has already loaded the information. It also appears that the mapping is then stored in ClassMetaData and CollectionMetaData objects, so if you wanted to find out about the mapping for a particular class you can call getClassMetaData passing either a Class or String(name of the entity) to get it. And have fun with it.
The configuration object is a pretty handy component to have, so I always like my HibernateUtil, or HibernateService class provide a method that returns the Configuration object, or with JPA annotations, the AnnotationConfiguration object.
This is not only helpful providing a SessionFactory and subseqently, a Hibernate Session, but can also be useful doing a SchemaExport and recreating your database based on changes to your annotated object model.
Here's a tutorial on creating a simple HibernateUtil class: