Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] EmbeddedId in superclass

Shaun,
    This looks ok at first glance.  The JPA Metamodel test model has 2 instances of an @EmbeddedId that is validating fine on both Entities and MappedSuperclasses using both PROPERTY and FIELD access, for reference the embeddable fields are int instead of String and I am using JOINED.

@MappedSuperclass
public abstract class CPU implements java.io.Serializable {
    protected CPUEmbeddedId id;
   
    // Any reference to this embedded key requires a bidirectional relationship (not unidirectional)
    @EmbeddedId
    @Column(name="CPU_ID")   
    public CPUEmbeddedId getId() {
        return id;
    }
...}

@Entity(name="MultiCoreCPUMetamodel")
@Table(name="CMP3_MM_MULTICORECPU")
public class MultiCoreCPU extends CPU {
...}

@Embeddable
public class CPUEmbeddedId implements Serializable {
    private int pk_part1;

    // This class is embedded inside a CPU MappedSuperclass (MultiCoreCPU Entity)
    @GeneratedValue(strategy=TABLE, generator="CPUEMBEDID_MM_TABLE_GENERATOR")
    @TableGenerator(
        name="CPUEMBEDID_MM_TABLE_GENERATOR",
        table="CMP3_MM_CPUEMBEDDID_SEQ",
        pkColumnName="SEQ_MM_NAME",
        valueColumnName="SEQ_MM_COUNT",
        pkColumnValue="CUST_MM_SEQ"
    )
    @Column(name = "CPU_ID", nullable = false)
    public int getPk_part1() {
        return pk_part1;
    }
..}

and

@Inheritance(strategy=JOINED)
@Entity(name="GalacticMetamodel")
@Table(name="CMP3_MM_GALACTIC")
@Access(AccessType.FIELD) // for 316991
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;
...}

@Embeddable
@Access(AccessType.FIELD) // for 316991
public class EmbeddedPK implements Serializable {
    // This class is embedded inside a Location Entity
    @GeneratedValue(strategy=TABLE, generator="EMBEDDEDPK_MM_TABLE_GENERATOR")
    @TableGenerator(
        name="EMBEDDEDPK_MM_TABLE_GENERATOR",
        table="CMP3_MM_EMBEDDEDPK_SEQ",
        pkColumnName="SEQ_MM_NAME",
        valueColumnName="SEQ_MM_COUNT",
        pkColumnValue="CUST_MM_SEQ"
    )
    //@Basic(optional = false)
    @Column(name = "GALACTIC_ID", nullable = false)
    private int pk_part1;
...}

thank you
/michael

Shawn Huang wrote:
Shawn Huang wrote:
i have these classes.

@Embeddable
public class ProductId implements Serializable{
    private String supp;
    private String lot;
}

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractStore implements Serializable {
    @EmbeddedId
    protected ProductId id;
    protected Integer dept;
}

@Entity
@Table(name = "SM_STORE")
public class SmStore extends AbstractStore implements Serializable {
}

when deploy to glassfish, eclipse link gives following exception:

Local Exception Stack: 
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions: 
---------------------------------------------------------

Exception [EclipseLink-74] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The primary key fields are not set for this descriptor.
Descriptor: RelationalDescriptor(com.comany.SmStore --> [DatabaseTable(SM_STORE)])

am i missing something.

_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top