Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] @Id ValidationException with EclipseLink

David,
	Hi, try moving your @Id, @SequenceGenerator and @GeneratedValue annotations up from the getId() function to your instance variable...

	private Integer id;


	I recall having to put annotations on either the instance variable only, or both the instance variable and the getter function - but the instance variable annotation should take precedence.

I have an example like yours and tested this scenario and got the same exception by moving the annotations down to the getId()

WORKING-------------------------------------------------------------------------------
    @Id
    @SequenceGenerator(name="STAT_SEQUENCE_CLASS", sequenceName="STAT_CLASS_SEQ_GENERATOR", allocationSize=25)
    @GeneratedValue(generator="STAT_SEQUENCE_CLASS")
	private BigDecimal id;

	public BigDecimal getId() {
		return this.id;
	}

[EL Config]: 2008.07.14 09:11:26.112--ServerSession(25300442)--Thread(Thread[main,5,main])--The alias name for the entity class [class org.eclipse.persistence.example.navigation.business.StatClass] is being defaulted to: StatClass.
[EL Config]: 2008.07.14 09:11:26.127--ServerSession(25300442)--Thread(Thread[main,5,main])--The column name for element [private java.math.BigDecimal org.eclipse.persistence.example.navigation.business.StatClass.id] is being defaulted to: ID.
EL Fine]: 2008.07.14 09:09:19.833--ClientSession(11644607)--Connection(7812797)--Thread(Thread[main,5,main])--INSERT INTO STAT_CLASS (ID, JDK_VERSION, CLASS_TYPE_CODE, MODIFIED, INTERNAL, NAME, LINES, VERSION, TEST, CLASS_PACKAGE, LABEL, CLASS_TYPE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
	bind => [14591, null, null, 2008-07-03, null, EqualsNode, 79, concrete, 0, 1069, 1001, null]


BROKEN--------------------------------------------------------------------------------


	private BigDecimal id;

    @Id
    @SequenceGenerator(name="STAT_SEQUENCE_CLASS", sequenceName="STAT_CLASS_SEQ_GENERATOR", allocationSize=25)
    @GeneratedValue(generator="STAT_SEQUENCE_CLASS")
	public BigDecimal getId() {
		return this.id;
	}



Caused by: Exception [EclipseLink-7161] (Eclipse Persistence Services - 1.0 (Build SNAPSHOT - 20080708)): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class org.eclipse.persistence.example.navigation.business.StatClass] 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 please make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
	at org.eclipse.persistence.exceptions.ValidationException.noPrimaryKeyAnnotationsFound(ValidationException.java:1234)


	thank you
	/michael

-----Original Message-----
From: David Nedrow [mailto:dnedrow@xxxxxxx]
Sent: Sunday, July 13, 2008 23:09
To: List - EclipseLink Users
Subject: [eclipselink-users] @Id ValidationException with EclipseLink


I've got about 10 classes that I have implemented via EclipseLink  
(1.0) annotations that all appear to work fine.

I added a new entity, but now I get the following annotation error  
when trying to deploy the app in GlassFish (V2.1)...

Deploying application in domain failed; Exception [EclipseLink-28018]  
(Eclipse Persistence Services - 1.0 (Build 1.0 - 20080707)):  
org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [NetConfPU]  
failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence  
Services - 1.0 (Build 1.0 - 20080707)):  
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class  
com.foo.ncs.argfrp.jpa.netconf.AclAddrDst] 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 please make  
sure that you do not have mixed access-type (both fields and  
properties annotated) in your entity class hierarchy.


So far as I can tell, I've done everything the same for the entities  
I've constructed that work fine.

Can anyone see a problem with what I have below?

/* AbstractAclAddrDst.java */

package com.foo.ncs.argfrp.jpa.netconf;

//~--- JDK imports  
------------------------------------------------------------

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.SequenceGenerator;

/**
* AbstractAclAddrDst entity provides the base persistence definition  
of the
* AclAddrDst entity.
*
*/
@MappedSuperclass public abstract class AbstractAclAddrDst implements  
java.io.Serializable {

// Fields
private Integer id;
private FilterAccess filterAccess;
private Integer address;

// Constructors

/** default constructor */
public AbstractAclAddrDst() {}

/** full constructor */
public AbstractAclAddrDst(Integer id, FilterAccess filterAccess,  
Integer address) {
this.id = id;
this.filterAccess = filterAccess;
this.address = address;
}

// Property accessors

/**
* Method description
*
*
* @return
*/
@SequenceGenerator(name = "ACLADDRDST_SEQ", sequenceName =  
"acl_addr_dst_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator =  
"ACLADDRDST_SEQ")
@Id @Column(
name = "id",
unique = true,
nullable = false
)
public Integer getId() {
return this.id;
}

/**
* Method description
*
*
* @param id
*/
public void setId(Integer id) {
this.id = id;
}

/**
* Method description
*
*
* @return
*/
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "filter_accessid", nullable = false)
public FilterAccess getFilterAccess() {
return this.filterAccess;
}

/**
* Method description
*
*
* @param filterAccess
*/
public void setFilterAccess(FilterAccess filterAccess) {
this.filterAccess = filterAccess;
}

/**
* Method description
*
*
* @return
*/
@Column(name = "address", nullable = false)
public Integer getAddress() {
return this.address;
}

/**
* Method description
*
*
* @param address
*/
public void setAddress(Integer address) {
this.address = address;
}
}


//~ Formatted in Sun Code Convention on 2008-07-13



and the concrete class...

/* AclAddrDst.java */


package com.foo.ncs.argfrp.jpa.netconf;

//~--- JDK imports  
------------------------------------------------------------

import javax.persistence.Entity;
import javax.persistence.Table;

/**
* AclAddrDst entity.
*
*/
@Entity @Table(name = "acl_addr_dst")
public class AclAddrDst extends AbstractAclAddrDst implements  
java.io.Serializable {

// Constructors

/** default constructor */
public AclAddrDst() {}

/** full constructor */
public AclAddrDst(Integer id, FilterAccess filterAccess, Integer  
address) {
super(id, filterAccess, address);
}
}


//~ Formatted in Sun Code Convention on 2008-07-13

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


Back to the top