使用EclipseLink JPA-RS的静态嵌套类时遇到问题。我有一个简单的JPA实体类
@Entity
@XmlAccessorType(XmlAccessType.FIELD)
public class Inventory {
@Id
private Integer id;
@ElementCollection
private List<Item> items;
@Embeddable
@XmlAccessorType(XmlAccessType.FIELD)
public static class Item {
}
}
这是持久性单元中唯一的类。当我尝试通过GET请求检索实体时,我在日志中看到以下异常:
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)
似乎EclipseLink JAXB实现(MOXy)无法处理该类。我的理解是,在JPA中,只有实体类才需要是顶级类。属性允许使用静态嵌套类。
奇怪的是,这个类适用于普通的EclipseLink。这是否意味着JPA-RS有自己的处理JPA类的方法?是否可以将其与示例类进行协调?
我正在使用EclipseLink 2.4.2(以及Jersey 1.18.2作为JAX-RS实现,如果这很重要)