1

I have a problem using static nested classes with EclipseLink JPA-RS. I have a simple JPA entity class

@Entity
@XmlAccessorType(XmlAccessType.FIELD)
public class Inventory {

    @Id
    private Integer id;

    @ElementCollection
    private List<Item> items;

    @Embeddable
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Item {

    }

}

This is the only class in the persistence unit. When I try to retrieve an entity via GET request I see the following exception in the log:

Dec 6, 2014 4:50:38 AM org.eclipse.persistence.jpa.rs.util.JPARSLogger exception
FINER: An Exception was thrown while creating a JPA persistence context for persistence unit: [inventory]: [Exception [EclipseLink-50007] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Name collision.  Two classes have the XML type with uri  and name item.]
Local Exception Stack: 
Exception [EclipseLink-50007] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.JAXBException
Exception Description: Name collision.  Two classes have the XML type with uri  and name item.
    at org.eclipse.persistence.exceptions.JAXBException.nameCollision(JAXBException.java:213)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processTypeQName(AnnotationsProcessor.java:1727)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.buildTypeInfo(AnnotationsProcessor.java:754)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.postBuildTypeInfo(AnnotationsProcessor.java:680)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.buildNewTypeInfo(AnnotationsProcessor.java:4614)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processPropertyTypes(AnnotationsProcessor.java:1058)
    at org.eclipse.persistence.jaxb.compiler.AnnotationsProcessor.processPropertyTypes(AnnotationsProcessor.java:1005)
    at org.eclipse.persistence.jaxb.compiler.XMLProcessor.processXML(XMLProcessor.java:424)
    at org.eclipse.persistence.jaxb.compiler.Generator.<init>(Generator.java:103)
    at org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext$MetadataContextInput.createContextState(DynamicJAXBContext.java:235)
    at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:169)
    at org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext.<init>(DynamicJAXBContext.java:70)
    at org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory.createContextFromOXM(DynamicJAXBContextFactory.java:347)
    at org.eclipse.persistence.jpa.rs.PersistenceContext.createDynamicJAXBContext(PersistenceContext.java:256)
    at org.eclipse.persistence.jpa.rs.PersistenceContext.<init>(PersistenceContext.java:169)
    at org.eclipse.persistence.jpa.rs.PersistenceFactoryBase.bootstrapPersistenceContext(PersistenceFactoryBase.java:56)
    at org.eclipse.persistence.jpa.rs.PersistenceFactoryBase.get(PersistenceFactoryBase.java:133)
    at org.eclipse.persistence.jpa.rs.resources.common.AbstractResource.getPersistenceContext(AbstractResource.java:206)
    at org.eclipse.persistence.jpa.rs.resources.common.AbstractEntityResource.find(AbstractEntityResource.java:92)
    at org.eclipse.persistence.jpa.rs.resources.unversioned.EntityResource.find(EntityResource.java:52)

It seems that EclipseLink JAXB implementation (MOXy) is not able to process the class. My understanding is that in JPA only entity classes are required to be top-level classes. Static nested classes are allowed for attributes.

What is weird is that this class works fine with plain EclipseLink. Does this mean that JPA-RS has its own way of handling JPA classes? Is it possible to reconcile it with the exemplar class?

I am using EclipseLink 2.4.2 (and Jersey 1.18.2 as JAX-RS implementation, if that matters)

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57

0 Answers0