openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Lee" <allee8...@gmail.com>
Subject Re: Bug in Enhancer?
Date Mon, 19 May 2008 15:00:38 GMT
Stephen,

It looks like you are "multiplexing" multiple persistence properties into a
single collection type. I believe this is at least violating to the
following JPA spec:

---------------------------------------
2.1.1 Persistent Fields and Properties
....
It is required that the entity class follow the method signature conventions
for JavaBeans read/write properties (as defined by the JavaBeans
Introspector class) for persistent properties when persistent properties are
used.

In this case, for every persistent property property of type T of the
entity, there is a getter method, getProperty, and setter method
setProperty. For boolean properties, isProperty is an alternative name for
the getter method.[3]

For single-valued persistent properties, these method signatures are:
• T getProperty()
• void setProperty(T t)

Collection-valued persistent fields and properties must be defined in terms
of one of the following collection-valued interfaces regardless of whether
the entity class otherwise adheres to the JavaBeans method conventions noted
above and whether field or property-based access is used:
java.util.Collection, java.util.Set, java.util.List[4], java.util.Map.[5]

For collection-valued persistent properties, type T must be one of these
collection interface types in the method signatures above. Generic variants
of these collection types may also be used (for example, Set<Order>).

2.1.4 Primary Keys and Entity Identity

A simple (i.e., non-composite) primary key must correspond to a single
persistent field or property of the entity class. The Id annotation is used
to denote a simple primary key. See section 9.1.8.

A composite primary key must correspond to either a single persistent field
or property or to a set of such fields or properties as described below. A
primary key class must be defined to represent a composite primary key.
Composite primary keys typically arise when mapping from legacy databases
when the
database key is comprised of several columns. The EmbeddedId and IdClass
annotations are used to denote composite primary keys. See sections 9.1.14
and 9.1.15.

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. In general, however, approximate numeric
types (e.g., floating point types) should never be used in primary keys.
Entities whose primary keys use types other than these will not be portable.
If generated primary keys are used, only integral types will be portable. If
java.util.Date is used as a primary key field or property, the temporal type
should be specified as DATE.
---------------------------------------
Hope this help.
Albert Lee.

On Mon, May 19, 2008 at 8:25 AM, Leake, Stephen <stephenleake@fairisaac.com>
wrote:

> If I have the following class the enhancer will enhance it correctly:
>
> @Entity(name = "TEST")
>
> public class Test {
>
>
>
>      String name;
>
>      String description;
>
>
>
>
>
>      public Test(){
>
>      }
>
>
>
>      @Basic
>
>      @Column(name = "DESCRIPTION", length = 32)
>
>      public String getDescription() {
>
>            return description;
>
>      }
>
>
>
>      public void setDescription(String description) {
>
>            this.description = description;
>
>      }
>
>
>
>      @Id
>
>      @Column(name = "NAME", length = 10)
>
>      public String getLinkTypeCode() {
>
>            return name;
>
>      }
>
>
>
>      public void setLinkTypeCode(String name) {
>
>            this.name = name;
>
> }
>
>
>
> }
>
>
>
> If I change this class to the following the Enhancer will fail with a
> NullPointerException:
>
>
>
> @Entity(name = "TEST")
>
> public class Test {
>
>
>
>      private ArrayList fieldList = new ArrayList();
>
>
>
>
>
>      public Test(){
>
>      }
>
>
>
>      @Basic
>
>      @Column(name = "DESCRIPTION", length = 32)
>
>      public String getDescription() {
>
>            return (String) fieldList.get(0);
>
>      }
>
>
>
>      public void setDescription(String description) {
>
>            fieldList.set(0, description);
>
>      }
>
>
>
>      @Id
>
>      @Column(name = "NAME", length = 10)
>
>      public String getLinkTypeCode() {
>
>            return (String) fieldList.get(1);
>
>      }
>
>
>
>      public void setLinkTypeCode(String name) {
>
>            fieldList.set(1, name);
>
>      }
>
>
>
> }
>
>
>
> Interestingly, if I store just one field in the ArrayList the Enhancer
> task will work. Enhancement only fails when more than one field is being
> stored in the ArrayList. Enhancement will also fail if I try to store
> the second field in a different ArrayList.
>
>
>
>
>
> The error generated by the Enhancer task is below
>
> [openjpac] <openjpa-1.0.3-SNAPSHOT-r420667:636088M nonfatal general
> error> org.apache.openjpa.util.GeneralException: An error occurred while
> enhancing com.test.entity.Test. Exception message: null
>
>  [openjpac] at
> org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:471)
>
>  [openjpac] at
> org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4362)
>
>  [openjpac] at
> org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:89)
>
>  [openjpac] at
> org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
>
>  [openjpac] at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
>
>  [openjpac] at org.apache.tools.ant.Task.perform(Task.java:364)
>
>  [openjpac] at org.apache.tools.ant.Target.execute(Target.java:341)
>
>  [openjpac] at org.apache.tools.ant.Target.performTasks(Target.java:369)
>
>  [openjpac] at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
>
>  [openjpac] at
> org.apache.tools.ant.Project.executeTarget(Project.java:1185)
>
>  [openjpac] at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecut
> or.java:40)
>
>  [openjpac] at
> org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTar
> gets(EclipseDefaultExecutor.java:32)
>
>  [openjpac] at
> org.apache.tools.ant.Project.executeTargets(Project.java:1068)
>
>  [openjpac] at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAnt
> Runner.java:423)
>
>  [openjpac] at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAn
> tRunner.java:137)
>
>  [openjpac] Caused by: java.lang.NullPointerException
>
>  [openjpac] at
> org.apache.openjpa.enhance.PCEnhancer.fromBackingFieldName(PCEnhancer.ja
> va:3693)
>
>  [openjpac] at
> org.apache.openjpa.enhance.PCEnhancer.replaceAndValidateFieldAccess(PCEn
> hancer.java:859)
>
>  [openjpac] at
> org.apache.openjpa.enhance.PCEnhancer.replaceAndValidateFieldAccess(PCEn
> hancer.java:808)
>
>  [openjpac] at
> org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:449)
>
>  [openjpac] ... 14 more
>
>
>
> BUILD FAILED
>
> C:\workspaces\modularitysvn2\com.fairisaac.edm.encore.links\build.xml:15
> : <openjpa-1.0.3-SNAPSHOT-r420667:636088M nonfatal general error>
> org.apache.openjpa.util.GeneralException: An error occurred while
> enhancing com.test.entity.Test. Exception message: null
>
>      at
> org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:176)
>
>      at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
>
>      at org.apache.tools.ant.Task.perform(Task.java:364)
>
>      at org.apache.tools.ant.Target.execute(Target.java:341)
>
>      at org.apache.tools.ant.Target.performTasks(Target.java:369)
>
>      at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
>
>      at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
>
>      at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecut
> or.java:40)
>
>      at
> org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTar
> gets(EclipseDefaultExecutor.java:32)
>
>      at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
>
>      at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAnt
> Runner.java:423)
>
>      at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAn
> tRunner.java:137)
>
> Caused by: <openjpa-1.0.3-SNAPSHOT-r420667:636088M nonfatal general
> error> org.apache.openjpa.util.GeneralException: An error occurred while
> enhancing com.test.entity.Test. Exception message: null
>
>      at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:471)
>
>      at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4362)
>
>      at
> org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:89)
>
>      at
> org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
>
>      ... 11 more
>
> Caused by: java.lang.NullPointerException
>
>      at
> org.apache.openjpa.enhance.PCEnhancer.fromBackingFieldName(PCEnhancer.ja
> va:3693)
>
>      at
> org.apache.openjpa.enhance.PCEnhancer.replaceAndValidateFieldAccess(PCEn
> hancer.java:859)
>
>      at
> org.apache.openjpa.enhance.PCEnhancer.replaceAndValidateFieldAccess(PCEn
> hancer.java:808)
>
>      at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:449)
>
>      ... 14 more
>
> --- Nested Exception ---
>
> <openjpa-1.0.3-SNAPSHOT-r420667:636088M nonfatal general error>
> org.apache.openjpa.util.GeneralException: An error occurred while
> enhancing com.test.entity.Test. Exception message: null
>
>      at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:471)
>
>      at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:4362)
>
>      at
> org.apache.openjpa.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:89)
>
>      at
> org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
>
>      at
> org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
>
>      at org.apache.tools.ant.Task.perform(Task.java:364)
>
>      at org.apache.tools.ant.Target.execute(Target.java:341)
>
>      at org.apache.tools.ant.Target.performTasks(Target.java:369)
>
>      at
> org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
>
>      at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
>
>      at
> org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecut
> or.java:40)
>
>      at
> org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTar
> gets(EclipseDefaultExecutor.java:32)
>
>      at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
>
>      at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAnt
> Runner.java:423)
>
>      at
> org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAn
> tRunner.java:137)
>
> Caused by: java.lang.NullPointerException
>
>      at
> org.apache.openjpa.enhance.PCEnhancer.fromBackingFieldName(PCEnhancer.ja
> va:3693)
>
>      at
> org.apache.openjpa.enhance.PCEnhancer.replaceAndValidateFieldAccess(PCEn
> hancer.java:859)
>
>      at
> org.apache.openjpa.enhance.PCEnhancer.replaceAndValidateFieldAccess(PCEn
> hancer.java:808)
>
>      at org.apache.openjpa.enhance.PCEnhancer.run(PCEnhancer.java:449)
>
>      ... 14 more
>
>
> This email and any files transmitted with it are confidential, proprietary
> and intended solely for the individual or entity to whom they are
> addressed.
> If you have received this email in error please delete it immediately.
>
>


-- 
Albert Lee.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message