This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 300626 - metamodel initialization fails with nested embeddables
Summary: metamodel initialization fails with nested embeddables
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
Depends on: 266912
Blocks: 298290
  Show dependency tree
 
Reported: 2010-01-24 18:52 EST by Michael Keith CLA
Modified: 2022-06-09 10:32 EDT (History)
3 users (show)

See Also:


Attachments
Metamodel : nested embeddable test model and case changes (11.19 KB, patch)
2010-11-30 15:55 EST, Michael OBrien CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Keith CLA 2010-01-24 18:52:48 EST
Have the following model:

@Entity
public class Employee {
    @Id private int id;

    @Embedded
    private ContactInfo contactInfo;
    //...
}
@Embeddable @Access(AccessType.FIELD)
public class ContactInfo {
    @Embedded
    private Address residence;
    
    @ManyToOne
    private Phone primaryPhone;
    
    @ManyToMany
    @MapKey(name = "type")
    private Map<String, Phone> phones;
    //...
}
@Embeddable @Access(AccessType.FIELD)
public class Address {
    private String street; 
    private String city; 
    private String state;
    //...
}
@Entity
public class Phone {
    @Id String num;
    
    @ManyToMany(mappedBy = "contactInfo.phones")
    List<Employee> employees;
    
    String type;
    //...
}

Get the following exception when trying to deploy:

     [exec] Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metamodel.EmbeddableTypeImpl cannot be cast to org.eclipse.persistence.internal.jpa.metamodel.IdentifiableTypeImpl
     [exec]     at org.eclipse.persistence.internal.jpa.metamodel.ManagedTypeImpl.initialize(ManagedTypeImpl.java:1152)
     [exec]     at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.initialize(MetamodelImpl.java:399)
     [exec]     at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.<init>(MetamodelImpl.java:101)
     [exec]     at org.eclipse.persistence.internal.jpa.metamodel.MetamodelImpl.<init>(MetamodelImpl.java:120)
     [exec]     at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.getMetamodel(EntityManagerSetupImpl.java:1939)
     [exec]     at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:385)
     [exec]     ... 58 more
Comment 1 Michael OBrien CLA 2010-11-26 17:40:36 EST
>Model
@Inheritance(strategy=JOINED)
@Entity(name="GalacticMetamodel")
@Table(name="CMP3_MM_GALACTIC")
@Access(AccessType.FIELD) // for 316991
/**
 * Note that this Entity inherits from a Transient superclass (a non-entity, non-mappedSuperclass)
 * The Position class will be a BasicType (with no attributes outside of its Java class).
 * The Metamodel API will therefore not allow inheritance of any attributes into subclasses.
 * Any attempt to access attributes of Position via GalacticPosition will get an expected IAE.
 */
public class GalacticPosition extends Position implements java.io.Serializable {
    private static final long serialVersionUID = 1395818966377137158L;

    // Any reference to this embedded key requires a bidirectional relationship (not unidirectional)
    @EmbeddedId
    @Column(name="GALACTIC_ID")    
    protected EmbeddedPK primaryKey;
    
    @Embedded
    private Observation observation;
...}

@Embeddable
public class Observation {
    // This class is embedded inside a GalacticPosition
    
    // nested embeddable
    @Embedded
    private ObservationDetail detail;
...}

@Embeddable
public class ObservationDetail {
    private String data;
...}
Comment 2 Michael OBrien CLA 2010-11-26 17:44:30 EST
>Nested embeddables initalize OK and pass through Metatdata and Metamodel processing in predeploy()
>after a full predeploy/deploy we set the root of the nested embeddable on the EntityType
this	EntityTypeImpl<X>  (id=425)	
  descriptor	RelationalDescriptor  (id=439)	
  javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition) (id=440)
  members	HashMap<K,V>  (id=441)	
    table	HashMap$Entry<K,V>[16]  (id=443)	
      [3]	HashMap$Entry<K,V>  (id=447)	
        key	"observation" (id=450)	
        value	SingularAttributeImpl<X,T>  (id=433)	
          elementType	EmbeddableTypeImpl<X>  (id=130)	
          managedType	EntityTypeImpl<X>  (id=425)	
          mapping	AggregateObjectMapping  (id=434)	

>Later in our extended test case
Thread [Thread-5] (Suspended)	
	MetamodelMetamodelTest.testEmbeddableType() line: 1544	

>We see that the Metamodel has been initialized property
>The nested embeddable hierarchy exists on the ManagedType
>in the embeddables map as a SingularAttribute on the EmbeddableType root
metamodel	MetamodelImpl  (id=70)	
 embeddables	LinkedHashMap<K,V>  (id=113)	
  table	HashMap$Entry<K,V>[16]  (id=697)	
   [4]	LinkedHashMap$Entry<K,V>  (id=699)	
    key	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Observation) (id=132)	
    value	EmbeddableTypeImpl<X>  (id=130)	
     javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Observation) (id=132)	
     members	HashMap<K,V>  (id=712)	
      size	3	
      table	HashMap$Entry<K,V>[16]  (id=716)	
       [2]	HashMap$Entry<K,V>  (id=719)	
        key	"detail" (id=722)	
        value	SingularAttributeImpl<X,T>  (id=226)	
         elementType	EmbeddableTypeImpl<X>  (id=160)	
          descriptor	RelationalDescriptor  (id=159)	
          javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.ObservationDetail) (id=161)	
         managedType	EmbeddableTypeImpl<X>  (id=130)	
          descriptor	RelationalDescriptor  (id=128)	
          javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Observation) (id=132)	
         mapping	AggregateObjectMapping  (id=227)	

>and as a SingularAttribute on the EmbeddableType attribute on the managedType EntityType parent on the metamodel
metamodel	MetamodelImpl  (id=70)	
 entities	LinkedHashMap<K,V>  (id=118)	
  size	17	
   [16]	LinkedHashMap$Entry<K,V>  (id=748)	
    after	LinkedHashMap$Entry<K,V>  (id=765)	
     key	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition) (id=440)	
     value	EntityTypeImpl<X>  (id=425)	
      javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.GalacticPosition) (id=440)	
      members	HashMap<K,V>  (id=441)	
       size	5	
       table	HashMap$Entry<K,V>[16]  (id=443)	
        [3]	HashMap$Entry<K,V>  (id=447)	
         key	"observation" (id=450)	
         value	SingularAttributeImpl<X,T>  (id=433)	
          elementType	EmbeddableTypeImpl<X>  (id=130)	
           descriptor	RelationalDescriptor  (id=128)	
           javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Observation) (id=132)	
           members	HashMap<K,V>  (id=712)	
            size	3	
            table	HashMap$Entry<K,V>[16]  (id=716)	
             [2]	HashMap$Entry<K,V>  (id=719)	
              key	"detail" (id=722)	
              value	SingularAttributeImpl<X,T>  (id=226)	
               elementType	EmbeddableTypeImpl<X>  (id=160)	
                descriptor	RelationalDescriptor  (id=159)	
                javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.ObservationDetail) (id=161)	
                members	HashMap<K,V>  (id=609)	
                metamodel	MetamodelImpl  (id=70)	
               managedType	EmbeddableTypeImpl<X>  (id=130)	
                descriptor	RelationalDescriptor  (id=128)	
                javaClass	Class<T> (org.eclipse.persistence.testing.models.jpa.metamodel.Observation) (id=132)	
                members	HashMap<K,V>  (id=712)	
                metamodel	MetamodelImpl  (id=70)	
               mapping	AggregateObjectMapping  (id=227)	
          managedType	EntityTypeImpl<X>  (id=425)	
          mapping	AggregateObjectMapping  (id=434)
Comment 3 Michael OBrien CLA 2010-11-30 15:55:52 EST
Created attachment 184182 [details]
Metamodel : nested embeddable test model and case changes
Comment 4 Michael OBrien CLA 2010-11-30 16:52:15 EST
>See test model additions in SVN rev# 8587
https://fisheye2.atlassian.com/changelog/eclipselink/?cs=8587
>Wiki models pending
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:32:39 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink