You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by pdd <pb...@gmail.com> on 2009/08/02 11:28:13 UTC

Re: overriding accesors in entity needs tranisent declaration

Digging further into this, there is a major difference in the way the entity
class is instantiated by EciplseLink versus OpenJPA. 
When using eclipselink w/o the transient declaration, the entity class's
overridden setters are called (which in turn call super).
While using OpenJPA with transient declaration for overridden accessors,
only the setters for the super class are called and the overridden setters
are never called. This causes the application to break which depends on the
initialization of non-persistent state in the entity class during the set*.

As an example, lets take the above simple test case. If I need to have a
non-persistent boolean field in UserModelImpl called adult and wrap it with
accessors as isAdult/setAdult. Then I can declare "adult" as a transient and
override the setAge/getAge such that the adult value can be set if the age
is more than 18, in UserModelImpl entity class.
public void setAge(int age) {
    if(age > 18) {
        adult = true;
    }
    super.setAge(age);
}
This will not work with OpenJPA.
-- 
View this message in context: http://n2.nabble.com/overriding-accesors-in-entity-need-tranisent-declaration-tp3363414p3372112.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: overriding accesors in entity needs tranisent declaration

Posted by pdd <pb...@gmail.com>.
Interestingly, Hibernate has similar behavior but little better in the sense
that it at least calls the overridden accessors. 
https://forum.hibernate.org/viewtopic.php?f=1&t=998837

Can this be fixed?
-- 
View this message in context: http://n2.nabble.com/overriding-accesors-in-entity-need-tranisent-declaration-tp3363414p3404818.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: overriding accesors in entity needs tranisent declaration

Posted by pdd <pb...@gmail.com>.
Here is the output from build-time enhancer.

Buildfile: build.xml

enhance:
 [openjpac] 463  UserAdminTestCase  WARN   [main] openjpa.MetaData - No
setter was found for method new in type
com.example.model.impl.UserModelBaseImpl while searching for persistent
properties. This method will be ignored. If you intended for this to be
persistent, please add a corresponding setter, or switch to field access for
this type hierarchy.
 [openjpac] 519  UserAdminTestCase  WARN   [main] openjpa.MetaData - Found
duplicate metadata or mapping for "class
com.example.model.impl.UserModelBaseImpl".  Ignoring.
 [openjpac] 523  UserAdminTestCase  WARN   [main] openjpa.MetaData - Found
duplicate metadata or mapping for "class
com.example.model.impl.UserModelImpl".  Ignoring.
 [openjpac] 582  UserAdminTestCase  WARN   [main] openjpa.Enhance - Detected
the following possible violations of the restrictions placed on property
access persistent types:
 [openjpac] "com.example.model.impl.UserModelBaseImpl" uses property access,
but its field "id" is accessed directly in method "isNew" defined in
"com.example.model.impl.UserModelBaseImpl".
 [openjpac] "com.example.model.impl.UserModelBaseImpl" uses property access,
but its field "active" is accessed directly in method "isActive" defined in
"com.example.model.impl.UserModelBaseImpl".

BUILD SUCCESSFUL
Total time: 1 second

I am using spring and load-time weaver of spring on tomcat at runtime. That
works fine with EclipseLink though.

-- 
View this message in context: http://n2.nabble.com/overriding-accesors-in-entity-need-tranisent-declaration-tp3363414p3396927.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: overriding accesors in entity needs tranisent declaration

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
  1. are you enhancing your entities at build-time? If not, try that first.
Does enhancement work without warning?



-----
Pinaki 
-- 
View this message in context: http://n2.nabble.com/overriding-accesors-in-entity-need-tranisent-declaration-tp3363414p3395146.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: overriding accesors in entity needs tranisent declaration

Posted by pdd <pb...@gmail.com>.
Can someone help please?
-- 
View this message in context: http://n2.nabble.com/overriding-accesors-in-entity-need-tranisent-declaration-tp3363414p3386510.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.