Community
Participate
Working Groups
Build Identifier: GlassFish Tools Bundle For Eclipse Version: 1.2 Based on Eclipse build id: M20090917-0800 Having an entity derived from a MappedSuperclass which contains a primarykeyclass does not work - results in following error: Caused by: Exception [EclipseLink-7163] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.ValidationException Exception Description: Entity class [class bsbs.MSC3] has both an @EmbdeddedId (on attribute [id]) and an @Id (on attribute []. Both ID types cannot be specified on the same entity. Note that the attribute name for the @Id-attribute is empty (which is right, because there is no @Id-attribute). Testclasses will be attached. Reproducible: Always Steps to Reproduce: 1. create the classes (attached) 2. generate tables from entities
here the classes to reproduce the behaviour: package bsbs; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Embeddable; @Embeddable public class TPK implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "INST", nullable = false, length = 2) private String id; @Column(name = "NL", nullable = false, length = 2) private String subid; public String getId() { return id; } public void setId(final String id) { this.id = id; } public String getSubid() { return subid; } public void setSubid(final String subid) { this.subid = subid; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((subid == null) ? 0 : subid.hashCode()); return result; } @Override public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final TPK other = (TPK) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (subid == null) { if (other.subid != null) return false; } else if (!subid.equals(other.subid)) return false; return true; } } package bsbs; import java.io.Serializable; import java.sql.Timestamp; import javax.persistence.EmbeddedId; import javax.persistence.MappedSuperclass; import javax.persistence.Version; @MappedSuperclass public class MSC3 implements Serializable { private static final long serialVersionUID = 1L; @Version private Timestamp version; @EmbeddedId protected TPK id; public MSC3() { super(); } public Timestamp getVersion() { return version; } public TPK getId() { return id; } public void setId(final TPK id) { this.id = id; } } package bsbs; import javax.persistence.Entity; @Entity public class T3 extends MSC3 { private static final long serialVersionUID = 1L; private String name; public T3() { super(); } public String getName() { return this.name; } public void setName(final String name) { this.name = name; } }
Setting target and priority. For details of what this means see: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
+1 I do have the same problem (EclipseLink v2). rgds. xavier
Created attachment 161305 [details] Simple eclipse project reproducing this bug We are also experiencing this bug, reproducable against versions 1.2.0 and 2.0.1
Created attachment 161306 [details] Simple eclipse project reproducing this bug We are also experiencing this bug, reproducable against versions 1.2.0 and 2.0.1
Sorry about the duplicate attachment, seemed to be having problems uploading.
>We have a composite EmbeddedId EmbeddedPK on the Entity parent of the MappedSuperclass CoordinateMS in our JPA test model >However, we do not have an EmbeddedID directly on a MappedSuperclass (CoordinateMS) >See UML class diagram http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#Mapped_Superclass_Test_Model >See Design Issue 100 http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#DI_100:_20100120:_EmbeddedId_on_MappedSuperclass_fails_metadata_validation_on_reserved_temp_metamodel_PK
>reproduction: move @EmbeddedId down from E:GalacticPosition to MS:CoordinateMS (It does not need to be composite) // Any reference to this embedded key requires a bidirectional relationship (not unidirectional) @EmbeddedId @Column(name="GALACTIC_ID") protected EmbeddedPK primaryKey; Exception Description: Entity class [class org.eclipse.persistence.testing.models.jpa.metamodel.CoordinateMS] has both an @EmbdeddedId (on attribute [primaryKey]) and an @Id (on attribute []. Both ID types cannot be specified on the same entity. at org.eclipse.persistence.exceptions.ValidationException.embeddedIdAndIdAnnotationFound(ValidationException.java:845) at org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.EmbeddedIdAccessor.process(EmbeddedIdAccessor.java:154) at org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor.processAccessors(MetadataDescriptor.java:1271) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.processAccessors(ClassAccessor.java:825) at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.processMetamodelDescriptor(MappedSuperclassAccessor.java:1088) at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage2(MetadataProject.java:1331) at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:461) at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:390) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:947) >Back in 2010 Jan - when we ran into this we decided on the following See EmbeddedIdAccessor:154 - The fake table name inserted so that we can process metamodel types is leaking into metadataprocessing. Either skip validation for this reserved temporary PK or delay inserting it in metadata processing until after this step if not required for metamodel pre-processing.
>This validation exception is occurring because metadata processing does not expect the fake table names (previously we did not have descriptors for MappedSuperclasses - before we introduced the Metadata JPA 2.0 API) >The fix will be to "not count" the fake ID's or either not add them in the presence of an IdClass or EmbeddedID
Created attachment 161366 [details] Preliminary patch illustrating option 1 of 2 for handling the case where we have an existing MAPPED_SUPERCLASS_RESERVED_PK_NAME (IdClass should require similar) >Option 100-1: Ignore fake MappedSuperclass IDs If we check the id for our fake MappedSuperclass id as follows if (owningDescriptor.hasPrimaryKeyFields() && !owningDescriptor.getPrimaryKeyField().getQualifiedName().equalsIgnoreCase( MetadataConstants.MAPPED_SUPERCLASS_RESERVED_PK_NAME)) { throw ValidationException.embeddedIdAndIdAnnotationFound(getJavaClass(), getAttributeName(), owningDescriptor.getIdAttributeName()); } We get the following instead of the validation ex cmpPolicy CMP3Policy (id=154) descriptor RelationalDescriptor (id=124) fieldToAccessorMap null forceUpdate null keyClassFields null mappedClass null modificationDeferralLevel 2 nonDeferredCreateTime 0 pessimisticLockingPolicy null pkClass null pkClassName "org.eclipse.persistence.testing.models.jpa.metamodel.EmbeddedPK" (id=160) updateAllFields null >Option 100-2: Do not add fake MappedSuperclass IDs when IdClass or EmbeddedId will exist >Infeasible At this point we do not have the Id accessors populated yet - to check if (!metadataDescriptor.hasIdAccessor()) { relationalDescriptor.addPrimaryKeyFieldName(MetadataConstants.MAPPED_SUPERCLASS_RESERVED_PK_NAME); } m_idAccessors HashMap<K,V> (id=91) entrySet HashMap$EntrySet (id=128) size 0 Thread [main] (Suspended (breakpoint at line 467 in MetadataProject)) MetadataProject.addMetamodelMappedSuperclass(MetadataClass, MappedSuperclassAccessor) line: 467 EntityAccessor.addPotentialMappedSuperclass(MetadataClass, boolean) line: 188 EntityAccessor.discoverMappedSuperclassesAndInheritanceParents(boolean) line: 300 EntityAccessor.preProcess(boolean) line: 539 EntityAccessor.preProcess() line: 522 MetadataProject.processStage1() line: 1303 MetadataProcessor.processORMMetadata() line: 460 PersistenceUnitProcessor.processORMetadata(MetadataProcessor, boolean) line: 390 EntityManagerSetupImpl.predeploy(PersistenceUnitInfo, Map) line: 947 JavaSECMPInitializer(JPAInitializer).callPredeploy(SEPersistenceUnitInfo, Map, PersistenceInitializationHelper, String, String) line: 88 JavaSECMPInitializer.initPersistenceUnits(Archive, Map, PersistenceInitializationHelper) line: 256 JavaSECMPInitializer.initialize(Map) line: 216 >Solution 100: We will need to use option 1 - ignore validation exceptions when the existing Id is the temporary fake one for processing MappedSuperclasses MetadataConstants.MAPPED_SUPERCLASS_RESERVED_PK_NAME="__PK_METAMODEL_RESERVED_IN_MEM_ONLY_FIELD_NAME";
Created attachment 161616 [details] Option 2 patch for handling an EmbeddedId set directly on a MappedSuperclass >See option 2 for the case where the EmbeddedId is set on a mappedSuperclass child of an Entity/MappedSuperclass. http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/metamodel_api#Option_100-2:_Do_not_add_fake_MappedSuperclass_IDs_when_IdClass_or_EmbeddedId_will_exist
Created attachment 161683 [details] UML class diagram for extended test model (CPU(MS with @EmbeddedId) <-- MultiCoreCPU(E))
Created attachment 161684 [details] JPA Metamodel Test model additions/modifications patch >code reviewed by Guy >I'll check in tomorrow after the milestone build completes tonight
>see SVN Rev# 6784 http://fisheye2.atlassian.com/changelog/eclipselink/?cs=6784
>This fix will solve the issue in GlassFish 13557 (in EclipseLink 2.0.1) https://glassfish.dev.java.net/issues/show_bug.cgi?id=13557
http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Embedded_Id
Hi, How can I use the fixed version in Glassfish v3.0.1 ? Please help. Thank you.
>Xavier, verify that the EclipseLink startup log on predeploy() reads post SVN rev# 6784
10393900 for 2.0.x BP
Created attachment 186380 [details] 10330 backport off 2.0.2 6872
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink