You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Stefan Handschuh <in...@shandschuh.de> on 2008/01/01 16:47:55 UTC

@Externalizer in 1.0.1 does not work on persist

Assume there is a class MyObject with an java.lang.Integer constructor
and a method "public java.lang.Integer getCode()".
Also there is a second class, which will be persistet an which contains a field

@Persistent
@Externalizer("getCode")
private MyObject myObject;

If I try to persist a instance of this second class, the following error occurs:

Caused by: java.lang.ClassCastException: some.package.MyObject cannot
be cast to java.lang.Integer
       at org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcProvideField(ReflectingPersistenceCapable.java:98)
       at org.apache.openjpa.kernel.StateManagerImpl.provideField(StateManagerImpl.java:2959)
       at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2774)
       at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
       at org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
       at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
       at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
       at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
       ... 38 more


The same is reproducable with the code of the documentation (types:
URL, Class) concerning externalizers.

Re: @Externalizer in 1.0.1 does not work on persist

Posted by Stefan Handschuh <in...@shandschuh.de>.
Oh, thanks al lot - that helpd!


2008/1/1, Pinaki Poddar <pp...@apache.org>:
>
> Yes, that proves that persistent entity classes were being enhanced at
> runtime and now as the configuration explicitly disallows it (it is active
> by default) -- the exception is raised.
>
> Build-time enhancement is post-compilation step that modifies @Entity
> classes' bytecodes. A 'enhancener' tool is provided and the process is
> documented at
>
> http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
>
>
> Stefan Handschuh wrote:
> >
> > Well with the property you provided I event cant load the persistence
> > provider while getting an
> >
> > org.apache.openjpa.persistence.ArgumentException: The configuration
> > disallows runtime optimizations, but the following listed types were
> > not enhanced at build time or at class load time with a javaagent: ...
> >
> > 2008/1/1, Pinaki Poddar <pp...@apache.org>:
> >>
> >> Looks like enhancement of entity classes are taking place at runtime.
> >> Will it
> >> be possible to verify if the behavior differs for build-time enhancement?
> >>
> >> Runtime enhancement can be switched off with
> >>     <property name="openjpa.RuntimeUnenhancedClasses"
> >> value="unsupported"/>
> >>
> >>
> >> Stefan Handschuh wrote:
> >> >
> >> > Assume there is a class MyObject with an java.lang.Integer constructor
> >> > and a method "public java.lang.Integer getCode()".
> >> > Also there is a second class, which will be persistet an which contains
> >> a
> >> > field
> >> >
> >> > @Persistent
> >> > @Externalizer("getCode")
> >> > private MyObject myObject;
> >> >
> >> > If I try to persist a instance of this second class, the following
> >> error
> >> > occurs:
> >> >
> >> > Caused by: java.lang.ClassCastException: some.package.MyObject cannot
> >> > be cast to java.lang.Integer
> >> >        at
> >> >
> >> org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcProvideField(ReflectingPersistenceCapable.java:98)
> >> >        at
> >> >
> >> org.apache.openjpa.kernel.StateManagerImpl.provideField(StateManagerImpl.java:2959)
> >> >        at
> >> >
> >> org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2774)
> >> >        at
> >> > org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
> >> >        at
> >> >
> >> org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
> >> >        at
> >> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
> >> >        at
> >> > org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
> >> >        at
> >> >
> >> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
> >> >        ... 38 more
> >> >
> >> >
> >> > The same is reproducable with the code of the documentation (types:
> >> > URL, Class) concerning externalizers.
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/%40Externalizer-in-1.0.1-does-not-work-on-persist-tp14567517p14568581.html
> >> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/%40Externalizer-in-1.0.1-does-not-work-on-persist-tp14567517p14568733.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>

Re: @Externalizer in 1.0.1 does not work on persist

Posted by infinity2heaven <in...@gmail.com>.
Thanks for the note. This will add an extra step while running individual
tests through eclipse (yes, I have the maven openjpa:enhance configured).

It looks like openjpa's enhancement itself has so many issues and I'd advice
to update the documentation to clarify these issues and highlight potential
risks.

On a second note, openjpa should raise erriors on app startup due to
unexpected conditions, not silently log warnings in "trace" mode. Hibernate
*always* checks all the mappings, down to the named queries.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Externalizer-in-1-0-1-does-not-work-on-persist-tp216632p6436357.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: @Externalizer in 1.0.1 does not work on persist

Posted by Rick Curtis <cu...@gmail.com>.
This is slightly tangental, but I'm going to recommend staying far far away
from RuntimeEnhancement. There are numerous known issues with that
enhancement strategy and you'll save yourself a number of headaches if you
stay away from it. I'd set the following property[1] to disable this
support.

[1] <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>

Thanks,
Rick

On Fri, Jun 3, 2011 at 12:10 PM, infinity2heaven
<in...@gmail.com>wrote:

> I get two very different errors when using the default RuntimeEnhancement
> and
> using build-time enhancements:
>
> Runtime:
> I get a classCast for my entity Foo.
> java.lang.ClassCastException:
> org.apache.openjpa.enhance.ReflectingPersistenceCapable incompatible with
> xxx.entity.Foo
>
> Build-time:
> App doesn't load.
> java.lang.NoSuchMethodError: xxx/BaseEntity.pcGetManagedFieldCount()I
>        at xxx.entity.ProfileLoadError.<clinit>(ProfileLoadError.java)
>        at java.lang.J9VMInternals.initializeImpl(Native Method)
>        at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
>        at java.lang.Class.forNameImpl(Native Method)
>        at java.lang.Class.forName(Class.java:136)
>
> My persistence.xml
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
>        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
>        version="1.0">
>
>        <persistence-unit name="tcms-profile"
> transaction-type="RESOURCE_LOCAL" >
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
>                <class>xxx.jpa.BaseEntity</class>
>        <class>xxx.entity.Foo</class>
>                <class>xxx.entity.ProfileAudit</class>
>                <class>xxx.entity.ProfileAuditDetail</class>
>
>                <properties>
>                        <property name="openjpa.jdbc.Schema" value="xyz"/>
>                </properties>
>        </persistence-unit>
> </persistence>
>
> What am I missing?
>
> Really. Two different errors based on openjpa's "enhancement."
>
-- 
*Rick Curtis*

Re: @Externalizer in 1.0.1 does not work on persist

Posted by infinity2heaven <in...@gmail.com>.
I was able to run my tests (and the app) by removing BaseEntity entirely. It
seems like openjpa has issues with @MappedSuperClass. I 
https://issues.apache.org/jira/browse/OPENJPA-2003 raised a bug  on this
earlier last month and this problem continues to show in different
scenarios. 

I even copied BaseEntity into the same package as all other entities and now
I get an initialization error:

java.lang.NoClassDefFoundError: xxx.SomeEntity (initialization failure)
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)


@MappedSuperclass
public class BaseEntity {

}

Do I raise another jira bug?

--
View this message in context: http://openjpa.208410.n2.nabble.com/Externalizer-in-1-0-1-does-not-work-on-persist-tp216632p6436252.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: @Externalizer in 1.0.1 does not work on persist

Posted by Michael Dick <mi...@gmail.com>.
infinity2heaven wrote:
> 
> Runtime:
> I get a classCast for my entity Foo.
> java.lang.ClassCastException:
> org.apache.openjpa.enhance.ReflectingPersistenceCapable incompatible with
> xxx.entity.Foo
> 

The runtime subclassing enhancer didn't run for Foo. If you enable trace
(openjpa.Log=DefaultLevel=TRACE) the classes which are enhanced should be
printed. 


infinity2heaven wrote:
> 
> Build-time:
> App doesn't load.
> java.lang.NoSuchMethodError: xxx/BaseEntity.pcGetManagedFieldCount()I
> 	at xxx.entity.ProfileLoadError.<clinit>(ProfileLoadError.java)
> 	at java.lang.J9VMInternals.initializeImpl(Native Method)
> 	at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
> 	at java.lang.Class.forNameImpl(Native Method)
> 	at java.lang.Class.forName(Class.java:136)
> 

This time it's BaseEntity that didn't get enhanced. The persistence.xml
lists xxxx.jpa.BaseEntity, but in this message it's just xxx/BateEntity.
It's probably just the way you copied in the stack, but it might be worth
making sure that they match. 

Enabling trace in this case may also help. You probably only need to enable
trace for the enhancer though : 
openjpa.Log=Enhance=TRACE,MetaData=TRACE should be a good start. 

-mike

--
View this message in context: http://openjpa.208410.n2.nabble.com/Externalizer-in-1-0-1-does-not-work-on-persist-tp216632p6436221.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: @Externalizer in 1.0.1 does not work on persist

Posted by infinity2heaven <in...@gmail.com>.
I get two very different errors when using the default RuntimeEnhancement and
using build-time enhancements:

Runtime:
I get a classCast for my entity Foo.
java.lang.ClassCastException:
org.apache.openjpa.enhance.ReflectingPersistenceCapable incompatible with
xxx.entity.Foo

Build-time:
App doesn't load.
java.lang.NoSuchMethodError: xxx/BaseEntity.pcGetManagedFieldCount()I
	at xxx.entity.ProfileLoadError.<clinit>(ProfileLoadError.java)
	at java.lang.J9VMInternals.initializeImpl(Native Method)
	at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
	at java.lang.Class.forNameImpl(Native Method)
	at java.lang.Class.forName(Class.java:136)

My persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
	http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	version="1.0">

	<persistence-unit name="tcms-profile" transaction-type="RESOURCE_LOCAL" >
	
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>

		<class>xxx.jpa.BaseEntity</class>
        <class>xxx.entity.Foo</class>
		<class>xxx.entity.ProfileAudit</class>
		<class>xxx.entity.ProfileAuditDetail</class>
		
		<properties>
			<property name="openjpa.jdbc.Schema" value="xyz"/>
		</properties>
	</persistence-unit>
</persistence>

What am I missing?

Really. Two different errors based on openjpa's "enhancement." 

--
View this message in context: http://openjpa.208410.n2.nabble.com/Externalizer-in-1-0-1-does-not-work-on-persist-tp216632p6436083.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.

Re: @Externalizer in 1.0.1 does not work on persist

Posted by Pinaki Poddar <pp...@apache.org>.
Yes, that proves that persistent entity classes were being enhanced at
runtime and now as the configuration explicitly disallows it (it is active
by default) -- the exception is raised.

Build-time enhancement is post-compilation step that modifies @Entity
classes' bytecodes. A 'enhancener' tool is provided and the process is
documented at

http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance
 

Stefan Handschuh wrote:
> 
> Well with the property you provided I event cant load the persistence
> provider while getting an
> 
> org.apache.openjpa.persistence.ArgumentException: The configuration
> disallows runtime optimizations, but the following listed types were
> not enhanced at build time or at class load time with a javaagent: ...
> 
> 2008/1/1, Pinaki Poddar <pp...@apache.org>:
>>
>> Looks like enhancement of entity classes are taking place at runtime.
>> Will it
>> be possible to verify if the behavior differs for build-time enhancement?
>>
>> Runtime enhancement can be switched off with
>>     <property name="openjpa.RuntimeUnenhancedClasses"
>> value="unsupported"/>
>>
>>
>> Stefan Handschuh wrote:
>> >
>> > Assume there is a class MyObject with an java.lang.Integer constructor
>> > and a method "public java.lang.Integer getCode()".
>> > Also there is a second class, which will be persistet an which contains
>> a
>> > field
>> >
>> > @Persistent
>> > @Externalizer("getCode")
>> > private MyObject myObject;
>> >
>> > If I try to persist a instance of this second class, the following
>> error
>> > occurs:
>> >
>> > Caused by: java.lang.ClassCastException: some.package.MyObject cannot
>> > be cast to java.lang.Integer
>> >        at
>> >
>> org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcProvideField(ReflectingPersistenceCapable.java:98)
>> >        at
>> >
>> org.apache.openjpa.kernel.StateManagerImpl.provideField(StateManagerImpl.java:2959)
>> >        at
>> >
>> org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2774)
>> >        at
>> > org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
>> >        at
>> >
>> org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
>> >        at
>> org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
>> >        at
>> > org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
>> >        at
>> >
>> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
>> >        ... 38 more
>> >
>> >
>> > The same is reproducable with the code of the documentation (types:
>> > URL, Class) concerning externalizers.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/%40Externalizer-in-1.0.1-does-not-work-on-persist-tp14567517p14568581.html
>> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/%40Externalizer-in-1.0.1-does-not-work-on-persist-tp14567517p14568733.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Re: @Externalizer in 1.0.1 does not work on persist

Posted by Stefan Handschuh <in...@shandschuh.de>.
Well with the property you provided I event cant load the persistence
provider while getting an

org.apache.openjpa.persistence.ArgumentException: The configuration
disallows runtime optimizations, but the following listed types were
not enhanced at build time or at class load time with a javaagent: ...

2008/1/1, Pinaki Poddar <pp...@apache.org>:
>
> Looks like enhancement of entity classes are taking place at runtime. Will it
> be possible to verify if the behavior differs for build-time enhancement?
>
> Runtime enhancement can be switched off with
>     <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
>
>
> Stefan Handschuh wrote:
> >
> > Assume there is a class MyObject with an java.lang.Integer constructor
> > and a method "public java.lang.Integer getCode()".
> > Also there is a second class, which will be persistet an which contains a
> > field
> >
> > @Persistent
> > @Externalizer("getCode")
> > private MyObject myObject;
> >
> > If I try to persist a instance of this second class, the following error
> > occurs:
> >
> > Caused by: java.lang.ClassCastException: some.package.MyObject cannot
> > be cast to java.lang.Integer
> >        at
> > org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcProvideField(ReflectingPersistenceCapable.java:98)
> >        at
> > org.apache.openjpa.kernel.StateManagerImpl.provideField(StateManagerImpl.java:2959)
> >        at
> > org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2774)
> >        at
> > org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
> >        at
> > org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
> >        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
> >        at
> > org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
> >        at
> > org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
> >        ... 38 more
> >
> >
> > The same is reproducable with the code of the documentation (types:
> > URL, Class) concerning externalizers.
> >
> >
>
> --
> View this message in context: http://www.nabble.com/%40Externalizer-in-1.0.1-does-not-work-on-persist-tp14567517p14568581.html
> Sent from the OpenJPA Developers mailing list archive at Nabble.com.
>
>

Re: @Externalizer in 1.0.1 does not work on persist

Posted by Pinaki Poddar <pp...@apache.org>.
Looks like enhancement of entity classes are taking place at runtime. Will it
be possible to verify if the behavior differs for build-time enhancement?

Runtime enhancement can be switched off with
     <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
 

Stefan Handschuh wrote:
> 
> Assume there is a class MyObject with an java.lang.Integer constructor
> and a method "public java.lang.Integer getCode()".
> Also there is a second class, which will be persistet an which contains a
> field
> 
> @Persistent
> @Externalizer("getCode")
> private MyObject myObject;
> 
> If I try to persist a instance of this second class, the following error
> occurs:
> 
> Caused by: java.lang.ClassCastException: some.package.MyObject cannot
> be cast to java.lang.Integer
>        at
> org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcProvideField(ReflectingPersistenceCapable.java:98)
>        at
> org.apache.openjpa.kernel.StateManagerImpl.provideField(StateManagerImpl.java:2959)
>        at
> org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2774)
>        at
> org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
>        at
> org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:940)
>        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1892)
>        at
> org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1852)
>        at
> org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1770)
>        ... 38 more
> 
> 
> The same is reproducable with the code of the documentation (types:
> URL, Class) concerning externalizers.
> 
> 

-- 
View this message in context: http://www.nabble.com/%40Externalizer-in-1.0.1-does-not-work-on-persist-tp14567517p14568581.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.