[JPAContainer] IllegalArgumentException creating EntityProvider

Hi Folks,

I’m trying out JPAContainer for the first time and can’t get past this seemingly easy and basic problem:


Caused by: java.lang.IllegalArgumentException: The class is not an entity
	at com.vaadin.addon.jpacontainer.metadata.MetadataFactory.getEntityClassMetadata(MetadataFactory.java:84)
	at com.vaadin.addon.jpacontainer.provider.LocalEntityProvider.<init>(LocalEntityProvider.java:100)
	at com.vaadin.addon.jpacontainer.provider.LocalEntityProvider.<init>(LocalEntityProvider.java:86)
	at com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider.<init>(MutableLocalEntityProvider.java:68)
	at vortex.console.ui.PeopleTable.load(PeopleTable.java:159)
....truncated...

Here is the code triggering the problem:


EntityManager em = RequestHandler.getEntityManager();

	MutableLocalEntityProvider<Person> entityProvider =
		new MutableLocalEntityProvider<Person>(Person.class, em);

The “new MutableLocalEntityProvider(Person.class, em)” is the matching line for

at vortex.console.ui.PeopleTable.load(PeopleTable.java:159)

The EntityManager (em) is a Hibernate EM.

The Person class is auto-generated by Texo (http://wiki.eclipse.org/Texo) from an ECore model file. Texo takes care of generating JPA Annotations.

Here is the JPAContainer method were the exception occurs:


public <T> EntityClassMetadata<T> getEntityClassMetadata(
			Class<T> mappedClass) throws IllegalArgumentException {
		assert mappedClass != null : "mappedClass must not be null";
		if (mappedClass.getAnnotation(Entity.class) == null) {
			throw new IllegalArgumentException("The class is not an entity");
		}
		PersistentPropertyMetadata.AccessType accessType = determineAccessType(mappedClass);
		if (accessType == null) {
			throw new IllegalArgumentException(
					"The access type could not be determined");
		} else {
			return (EntityClassMetadata<T>) getClassMetadata(mappedClass,
					accessType);
		}
	}

The mappedClass.getAnnotation(Entity.class) appears to be java.lang.class.getAnnotation(). My guess is that perhaps the Texo generated annotations aren’t recognized by getAnnotation(). Texo generates annotations in an orm.xml (part of the JPA standard) file and does not put the annotations directly into the generated Java code like the Person.java class (attached). Is this a known issue? Is there a way to get the annotations in orm.xml to work with JPAContainer and the getAnnotation() method?

Any suggestions on this exception?
11945.java (10.6 KB)

Hello,

sorry to revive this old thread but it seems that the problem is still not fixed.

The problem here is that to use an entity class with JPAContainer, the entity mapping MUST be specified through annotations directly in the class. External mapping files like orm.xml are simply not supported.

In my opinion, this is a serious design flaw in JPAContainer. The reason for this incompatibility is that they didn’t use the Metamodel class provided by JPA to determine mapped entities and attributes, but go directly for the annotations in the entity class. If there are none, because the mappings are specified in an external file, the class will not be recognized as an entity.

Just a bit of background: For a long time, it was a requirement for the JPAContainer to support JPA 1, which does not have a metamodel that could be used for this. When the JPA 2 version of the container was made, apparently not all the metadata handling was updated in the migration.

If there is no ticket for this (see
this list
), please
create one
.