users@glassfish.java.net

JPA 2 Dynamic Metamodel Question

From: NBW <emailnbw_at_gmail.com>
Date: Tue, 2 Mar 2010 11:18:57 -0500

Hi,

Recently I've been working with using the new metamodel features in
JPA 2 w/Eclipslink bundled with GFv3. I've been successful at
generating and using static metamodel classes by running the
eclipselink CanonicalModelProcessor class.

However, I've not been successful obtaining and using a MetaModel
class dynamically as described here [1]. My code looks something like
this:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MyEntity> cq = cb.createQuery(MyEntity.class);
Metamodel m = em.getMetaModel;
Root<MyEntity> myEntityRoot = cq.from(MyEntity.class);
EntityType<MyEntity> MyEntity_ = m.entity(MyEntity.class);
cq.where(cb.equal(configParam.get(MyEntity_.name), "Bob"));
....

When I statically generate the metamodel classes and include them in
my code looks like this:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MyEntity> cq = cb.createQuery(MyEntity.class);
Root<MyEntity> myEntityRoot = cq.from(MyEntity.class);
cq.where(cb.equal(configParam.get(MyEntity_.name), "Bob"));

and MyEntity_.java is located in the same directory along side
MyEntity.java and it is part of my compile class path and they are
packaged and deployed in my WAR file.

The use of the static metamodels works fine. When trying the 'dynamic'
usage I get missing symbol issues. Do I have to still run the
eclipselink annotation processor and include the generated classes in
my compile time class path but not package them because they will be
created during predeployment? I guess I am a bit confused here, was I
hoping to get something from nothing?

Thanks,

-Noah



[1] - http://java.sun.com/javaee/6/docs/tutorial/doc/gjiup.html