entityManager.createQuery("Select e from "+MyEntity.class.getName()+" e") in glassfish

I've been using EJB3 with jboss for a long time - and I've got use to this way of writing my ejb3 persistence queries:

entityManager.createQuery("Select e from "+MyEntity.class.getName()+" e")

which is also convenient considering refactoring compared to "Select e from MyEntity e".

But the EJB3 persistence spec says this:

"Entities are designated in query strings by their entity names. The entity name is defined by the name
element of the Entity annotation (or the entity-name XML descriptor element), and defaults to
the unqualified name of the entity class. Entity names are scoped within the persistence unit and must be
unique within the persistence unit."

And glassfish complains about the fully qualified classnames - it just want the unqualified classname (without package information).

According to the spec - glassfish seems more correct to me - but the hibernate/jboss way of using fqn seems better to me - so I wonder, which one is really correct..

Update: class.getSimpleName() does the job - and keeps the refactoring possibility


ceyesuma said…
How do I create the query initially? to use
entityManager.createQuery....I dont know.
can I get an example to
create a string(query)
and setter
and getter
Sunil said…
thanks it was very helpful

Popular posts from this blog

My VNC based development environment with Visual Studio Code running on Ubuntu

Create PDF's in Angular / Typescript

Angular 5 - Ahead of Time build configuration for rollup