enhancing entity which is a subclass

5 messages Options
Embed this post
Permalink
pdd

enhancing entity which is a subclass

Reply Threaded More More options
Print post
Permalink
Everything works with EclipseLink and TopLink but fails with OpenJPA.

Tried with runtime as well as build time enhancement. The problem is the entity class is a subclass. In this test case, it is an empty class which inherits everything from the base class UserModelBaseImpl.

...
...
...
 [openjpac] Caused by: java.io.IOException: org.xml.sax.SAXException: file:/TestCase/build/web/WEB-INF/classes/META-INF/orm.xml [Location: Line: 19, C: 18]: Could not find property/field with the name "id" in type "com.example.model.impl.UserModelImpl".[java.lang.NoSuchMethodException: com.example.model.impl.UserModelImpl.getId()]
...
...
...
Caused by: java.lang.NoSuchMethodException: com.example.model.impl.UserModelImpl.getId()
        at java.lang.Class.getDeclaredMethod(Class.java:1937)
        at org.apache.openjpa.lib.util.J2DoPrivHelper$8.run(J2DoPrivHelper.java:288)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.parseField(XMLPersistenceMetaDataParser.java:1105)
        ... 46 more

The getId method exists in the parent class. In fact all methods/fields are defined in the parent base implementation. The orm.xml specifies PROPERTY access.

Is this is a bug?

Rick Curtis

Re: enhancing entity which is a subclass

Reply Threaded More More options
Print post
Permalink
Can you post snippets of your Entities and your persistence.xml file?

-Rick

On Mon, Jul 27, 2009 at 7:47 AM, pdd <[hidden email]> wrote:

>
> Everything works with EclipseLink and TopLink but fails with OpenJPA.
>
> Tried with runtime as well as build time enhancement. The problem is the
> entity class is a subclass. In this test case, it is an empty class which
> inherits everything from the base class UserModelBaseImpl.
>
> ...
> ...
> ...
>  [openjpac] Caused by: java.io.IOException: org.xml.sax.SAXException:
> file:/TestCase/build/web/WEB-INF/classes/META-INF/orm.xml [Location: Line:
> 19, C: 18]: Could not find property/field with the name "id" in type
> "com.example.model.impl.UserModelImpl".[java.lang.NoSuchMethodException:
> com.example.model.impl.UserModelImpl.getId()]
> ...
> ...
> ...
> Caused by: java.lang.NoSuchMethodException:
> com.example.model.impl.UserModelImpl.getId()
>        at java.lang.Class.getDeclaredMethod(Class.java:1937)
>        at
> org.apache.openjpa.lib.util.J2DoPrivHelper$8.run(J2DoPrivHelper.java:288)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at
>
> org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.parseField(XMLPersistenceMetaDataParser.java:1105)
>        ... 46 more
>
> The getId method exists in the parent class. In fact all methods/fields are
> defined in the parent base implementation. The orm.xml specifies PROPERTY
> access.
>
> Is this is a bug?
>
>
> --
> View this message in context:
> http://n2.nabble.com/enhancing-entity-which-is-a-subclass-tp3333612p3333612.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
pdd

Re: enhancing entity which is a subclass

Reply Threaded More More options
Print post
Permalink
Here are the relevant snippets.

persistence.xml fragment
-----------------------------
  <persistence-unit name="UserAdmin" transaction-type="RESOURCE_LOCAL">
    <!-- Explicitly define mapping file path, else Hibernate won't find the default -->
    <non-jta-data-source/>
    <mapping-file>META-INF/orm.xml</mapping-file>
    <!-- Prevent annotation scanning. In this app we are purely driven by orm.xml -->
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties/>
  </persistence-unit>


  <persistence-unit name="enhance" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>com.example.model.impl.UserModelImpl</class>
  </persistence-unit>

Entity class UserModelImpl
------------------------------
package com.example.model.impl;

public class UserModelImpl extends UserModelBaseImpl {

}

UserModelBaseImpl.java
---------------------------
package com.example.model.impl;

import com.example.model.UserModel;

public class UserModelBaseImpl implements UserModel {
        private long id = -1;
        private String firstName;
        private String lastName;
        private int age;
        private double wages;
        private boolean active;

        public int getAge() {
                return age;
        }

        public String getFirstName() {
                return firstName;
        }

        public long getId() {
                return id;
        }

...
...
...
        public void setAge(int age) {
                this.age = age;
        }

        public void setFirstName(String firstName) {
                this.firstName = firstName;
        }

        public void setId(long id) {
                this.id = id;
        }
...
...
...
}

orm.xml
----------
        <persistence-unit-metadata>
                <xml-mapping-metadata-complete/>
                <persistence-unit-defaults>
                        <access>PROPERTY</access>
                </persistence-unit-defaults>
        </persistence-unit-metadata>

        <package>com.example.model.impl</package>

        <entity class="UserModelImpl">
                <table name="User"/>
                <attributes>
                        <id name="id">
                                <generated-value strategy="IDENTITY"/>
                        </id>
                        <basic name="firstName"/>
                        <basic name="lastName"/>
                        <basic name="age"/>
                        <basic name="wages"/>
                        <basic name="active">
                                <column name="ACTIVE_"/>
                        </basic>
                        <transient name="new"/>
                </attributes>
        </entity>

Rick Curtis wrote:
Can you post snippets of your Entities and your persistence.xml file?

-Rick
Rick Curtis

Re: enhancing entity which is a subclass

Reply Threaded More More options
Print post
Permalink
After looking at the spec, it looks like you should be using the mapped-superclass XML descriptor on the UserModelBaseImpl class and com.example.model.impl.UserModelImpl needs to be added to your list of persistent classes.  See section 2.11 - 'Inheritance' for more details. Let me know how it goes!

-Rick
pdd

Re: enhancing entity which is a subclass

Reply Threaded More More options
Print post
Permalink
Thanks a lot Rick. It worked!

Rick Curtis wrote:
After looking at the spec, it looks like you should be using the mapped-superclass XML descriptor on the UserModelBaseImpl class and com.example.model.impl.UserModelImpl needs to be added to your list of persistent classes.  See section 2.11 - 'Inheritance' for more details. Let me know how it goes!

-Rick