persistence@glassfish.java.net

Re: _at_Id ValidationException with EclipseLink

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Mon, 14 Jul 2008 12:07:52 -0700

Crossposting from the thread about this issue from EclipseLink users
forums...



David,
        For workaround 2 - use an orm.xml annotation, I verified the following change if you don't want to move your annotations to your fields and keep your entities as-is.

Entity superclass
-----------------
@MappedSuperclass abstract public class StatAbstractClass implements Serializable {
        private BigDecimal id;

orm.xml
--------
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="1.0" xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd">
    <description>Workaround for http://bugs.eclipse.org/240679 </description>
    <package>org.eclipse.persistence.example.navigation.business</package>
    <entity name="StatClass" class="StatClass" access="PROPERTY">
    </entity>
</entity-mappings>

output
------
[EL Finest]: 2008.07.14 10:45:25.452--UnitOfWork(10625551)--Thread(Thread[main,5,main])--Execute query InsertObjectQuery(org.eclipse.persistence.example.navigation.business.StatClass_at_167c6fd)
[EL Fine]: 2008.07.14 10:45:25.452--ClientSession(26285376)--Connection(8304354)--Thread(Thread[main,5,main])--INSERT INTO STAT_CLASS (ID, JDK_VERSION, MODIFIED, INTERNAL, LINES, TEST, CLASS_TYPE_CODE, NAME, VERSION, LABEL, CLASS_TYPE, CLASS_PACKAGE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
        bind => [28160, null, 2008-07-03, null, 28, 0, null, DescriptorCompare, concrete, 1201, null, 2839]


thank you
/michael

-----Original Message-----
From: MICHAEL.OBRIEN_at_ORACLE.COM
Sent: Monday, July 14, 2008 10:18
To: EclipseLink User Discussions
Subject: RE: [eclipselink-users] @Id ValidationException with
EclipseLink - see new bug# 240679


David,
        After further investigation surrounding @MappedSuperclass (which I have just started to use today) with Guy, Gordon and Tom - your issue is a bug.

        We have raised bug# 240679 where you may track progress.
        http://bugs.eclipse.org/240679

        The workarounds can be either
                1) move (ALL) your annotations to your fields on your superclass - verified
                2) or define the attribute type on the descriptor to METHOD
                see : http://java.sun.com/javaee/5/docs/api/javax/persistence/AttributeOverride.html


        thank you for raising this issue.
        /michael



David Nedrow wrote:
> 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
>