0

I have a Entity class and jpa is throwing an Validation Exception saying primary key specified. I could not figure out why.

Please see the details below: * Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Predeployment of PersistenceUnit [default] failed. Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.ValidationException Exception Description: Entity class [class A] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.*

The entity class A:

@Access(AccessType.FIELD)
@Entity
@Cache(disableHits=true)
@Table(name="VT_INVALID_USERS")
public class A extends BharosaBaseBean implements java.io.Serializable {
    @SequenceGenerator(name="USERS_SEQ", allocationSize=1)
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO, generator="USERS_SEQ")
    @Column(name="USER_ID")
    protected Long userId;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="CREATE_TIME")
    protected Date createTime = new Date();

    public void setUserId( Long userId ) {
        this.userId = userId;
    }

    public Long getUserId( ) {
        return this.userId;
    }
}

The BharosaBaseBean class:

public abstract class BharosaBaseBean implements java.io.Serializable {
    abstract public Long getPKId();
}

The persistence file I have:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
    <persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
        <provider>
            org.eclipse.persistence.jpa.PersistenceProvider
        </provider>
        <mapping-file>orm.xml</mapping-file>
        <properties>
            <property name="eclipselink.logging.level" value="FINE"/>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
            <property name="javax.persistence.jdbc.url" value=" <url>"/>
            <property name="javax.persistence.jdbc.user" value="<user>"/>
            <property name="javax.persistence.jdbc.password" value="<pwd>"/>
            <property name="eclipselink.jdbc.read-connections.max" value="5"/>
            <property name="eclipselink.jdbc.read-connections.min" value="5"/>
            <property name="eclipselink.jdbc.write-connections.max" value="10"/>
            <property name="eclipselink.jdbc.wirte-connections.min" value="10"/>
            <property name="eclipselink.session.customizer" value="oracle.security.uas.core.common.toplink.SessionCustomizerForCLIRetryLogic"/>
            <property name="oaam.eclipselink.conn.health.validated.on.error" value="true"/>
            <property name="oaam.eclipselink.query.retry.attempt.count" value="3"/>
            <property name="oaam.eclipselink.delay.between.reconnect.attempts" value="5000"/>
            <property name="oaam.eclipselink.ping.sql" value="select 1 from dual"/>
        </properties>
    </persistence-unit>
</persistence>
jiii
  • 71
  • 4
  • Turn on EclipseLink Logging and set it to all or finest - it should log everything when it goes to deploy the persistence unit and show what it finds for the 'A' entity before it throws the exception. I'd guess you have a different A class on the class path that might be incomplete (an older version possibly) and that is causing the exception. – Chris Aug 03 '21 at 13:55

1 Answers1

0

Maybe you could try adding your base class to the persistence.xml file.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Did you mean to add BharosaBaseBean class inside the mapping file orm.xml specified in persistence.xml? – jiii Jul 31 '21 at 02:38
  • Check this topic: https://stackoverflow.com/questions/1780341/do-i-need-class-elements-in-persistence-xml – Mihael Mihov Jul 31 '21 at 07:40