persistence@glassfish.java.net

Re: "Invalid composite primary key specification"

From: Markus Fuchs <Markus.Fuchs_at_Sun.COM>
Date: Thu, 02 Aug 2007 13:19:49 -0700
Hi Jeffrey,

Entities should not use relationship fields as part of the primary key. The JPA spec says (please see 2.1.4.):

The primary key (or field or property of a composite primary key) should be one of the following types:
any Java primitive type; any primitive wrapper type; java.lang.String; java.util.Date;
java.sql.Date.

Try changing:

public abstract class Entity implements Serializable {
    @Id
    @Column (nullable = false, name="ENTITY_NAME")
    @XmlAttribute
    private String name;

    @Id
    @Column (nullable = false, name="PAGE_ID")    
    private String pageId;


    @Column (nullable = false, name="PAGE_ID")    
    @ManyToOne (cascade = CascadeType.ALL, insertable=false, updatable=false)
    private Page page = null;
...
}

public class EntityId implements Serializable {
    private String name;
    private String pageId;
...
}
   
-- markus.

Entity
Jeffrey Blattman wrote:
hi,

2.0-b56, i'm seeing this ...

Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [com.sun.portal.pom.EntityId] and those of the entity bean class [class com.sun.portal.pom.Entity] must correspond and their types must be the same. Also, ensure that you have specified id elements for the corresponding attributes in XML and/or an @Id on the corresponding fields or properties of the entity class.

i've attached the two classes. Entity has IDs name and page, and EntityId has fields name and page. same name, same type. i can zip the maven2 project so the problem can be reproduced, if that helps.

what am i missing?

thanks.