You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Steve <ra...@gmail.com> on 2012/03/06 17:21:47 UTC

ArgumentException calling entityManager.createQuery but enhancer has been run.

Hi all,

I'm trying to migrate away from Hibernate to OpenJPA. I have a Spring
3 and GWT web application that I run from eclipse.

I've added an enhancer builder to my eclipse project, and also enabled
the annotation processing, which all appears to be working OK. I have
generated "_" classes that I can use for queries and I get some
warnings about property access when I start the container (which is
running under Jetty btw).

However when I try to call entityManager.createQuery(criteriaQuery) it
fails with the following error:

<openjpa-2.1.1-r422266:1148538 nonfatal user error>
org.apache.openjpa.persistence.ArgumentException: This configuration
disallows runtime optimization, but the following listed types were
not enhanced at build time or at class load time with a javaagent: "

Which then goes on to list all of my classes that I thought were enhanced.

My persistence xml is pretty simple:

    <persistence-unit name="audit" transaction-type="RESOURCE_LOCAL">
        <class>classname.here</class>

        <properties>
            <property name="openjpa.DynamicEnhancementAgent" value="false" />
        </properties>
   </persistence-unit>

I've looked at the generated class files in eclipse's bin folder the
classes have they have definitely been enhanced as I can see
references to openjpa in the class files. I'm at a loss as to where to
go from here, I've been search the web and reading documentation and I
don't know what to try next. Any pointers would be gratefully
received.

Thank you,

Steve.

Re: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by Steve <ra...@gmail.com>.
Solution can be found here:

http://forum.springsource.org/showthread.php?58964-ClassCastException-when-using-JPA-result

Turns out that spring's load time weaver class is using the "wrong"
parent classloader. Creating my own subclass as suggested at the
bottom of the thread linked makes everything work!

Re: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by Steve <ra...@gmail.com>.
On 8 March 2012 10:01, Boblitz John <Jo...@bertschi.com> wrote:
> Hello Steve,
>
> You wrote orignally that your were migrating away from Hibernate, yet, in you most recent
> Posting, you have a Link to "audit/orm/HibernateServerDetail".
>
> Maybe this is part of the problem?
>

Not unless openJPA is reading class names ;). But seriously yes, this
used to be a class persisted by hibernate, but I've moved it over to
JPA annotations I just haven't renamed the class yet as I have enough
changes with the hibernate removal without doing name refactors at the
same time.

Having done lots of debugging through openJPA code I now know *why*
the openJPA code blows up, but how to fix it is a mystery.

The problem is that the PersistenceCapable interface appears to be
being loaded by two different class loaders, in the openJPA code there
is then a check to see if that class is assignable from the entity
class that has been loaded. Now despite the fact that the entity class
does implement the PersistenceCapable interface (I've checked using
the debugger) it's not the same one from the same class loader (or
parents) and so the check fails, which takes the code down the run
time enhancer route.

So my mission now is to figure out why this is the case and try and
stop that happening. Probably something to do with spring getting in
the way, I might try creating all the openJPA stack myself without
spring to see if that helps.

Any other suggestions welcome!

AW: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by Boblitz John <Jo...@BERTSCHI.com>.
> Von: Steve [mailto:rather.b.sailing@gmail.com] 
> Gesendet: Donnerstag, 8. März 2012 10:24
> An: users@openjpa.apache.org
> Betreff: Re: ArgumentException calling 
> entityManager.createQuery but enhancer has been run.
> 
> On 7 March 2012 10:53, afryer <ap...@hotmail.com> wrote:
> > I've had issues with eclipse not refreshing the class files after 
> > enhancement.  It might be worth manually refreshing your project by 
> > clicking your project and hitting F5 before running your 
> test case to 
> > make sure the enhanced class files are loaded by eclipse.
> 
> Thank you for the tip, to try and ensure that this isn't the 
> problem I've built and deployed the webapp in an external 
> tomcat server, that way I can find all the instances of my 
> classes and double check they are enhanced and the only 
> instance of my .class files definitely references to the 
> "org/apache/openjpa/enhance/PersistenceCapable"
> interface.
> 
> I also switched on jpa logging (<property name="openjpa.Log"
> value="DefaultLevel=TRACE" />) and I see the following log messages:
> 
> 1409  audit  TRACE  [main] openjpa.Enhance - 
> "audit/orm/HibernateServerDetail" requires runtime enhancement: false
> 
> So it looks like at least one part of openJPA thinks my 
> classes are properly enhanced however as soon as I try and 
> run a query I still the exception saying that my classes are 
> not enhanced at build time :(.
> 
> I'm totally stumped now as to what to try.
>

Hello Steve,

You wrote orignally that your were migrating away from Hibernate, yet, in you most recent
Posting, you have a Link to "audit/orm/HibernateServerDetail".

Maybe this is part of the problem?

Cheers,

 

John

---- 

Who is General Failure, and why is he reading my hard disk?


Re: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by Steve <ra...@gmail.com>.
On 7 March 2012 10:53, afryer <ap...@hotmail.com> wrote:
> I've had issues with eclipse not refreshing the class files after
> enhancement.  It might be worth manually refreshing your project by clicking
> your project and hitting F5 before running your test case to make sure the
> enhanced class files are loaded by eclipse.

Thank you for the tip, to try and ensure that this isn't the problem
I've built and deployed the webapp in an external tomcat server, that
way I can find all the instances of my classes and double check they
are enhanced and the only instance of my .class files definitely
references to the "org/apache/openjpa/enhance/PersistenceCapable"
interface.

I also switched on jpa logging (<property name="openjpa.Log"
value="DefaultLevel=TRACE" />) and I see the following log messages:

1409  audit  TRACE  [main] openjpa.Enhance -
"audit/orm/HibernateServerDetail" requires runtime enhancement: false

So it looks like at least one part of openJPA thinks my classes are
properly enhanced however as soon as I try and run a query I still the
exception saying that my classes are not enhanced at build time :(.

I'm totally stumped now as to what to try.

Re: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by afryer <ap...@hotmail.com>.
I've had issues with eclipse not refreshing the class files after
enhancement.  It might be worth manually refreshing your project by clicking
your project and hitting F5 before running your test case to make sure the
enhanced class files are loaded by eclipse.

--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-calling-entityManager-createQuery-but-enhancer-has-been-run-tp7349037p7351472.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by Steve <ra...@gmail.com>.
On 6 March 2012 23:23, afryer <ap...@hotmail.com> wrote:
> How did you configure an enhancer builder in eclipse?
>
> I'm doing a similar thing in eclipse using maven and m2e.  The enhancement
> is done with the openjpa maven plugin in the process-classes phase.
>

I've got the enhancer as an extra builder because I don't use maven.
I've set up an extra builder as per the instructions:

http://openjpa.apache.org/enhancement-with-eclipse.html

And I can tell it is working because the .class files have lots of
references to openJPA in them.

Re: ArgumentException calling entityManager.createQuery but enhancer has been run.

Posted by afryer <ap...@hotmail.com>.
How did you configure an enhancer builder in eclipse?

I'm doing a similar thing in eclipse using maven and m2e.  The enhancement
is done with the openjpa maven plugin in the process-classes phase.

--
View this message in context: http://openjpa.208410.n2.nabble.com/ArgumentException-calling-entityManager-createQuery-but-enhancer-has-been-run-tp7349037p7350335.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.