You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Joshua Jackson <jo...@gmail.com> on 2007/07/04 12:53:00 UTC

Enhancing a persistent class

Dear all,

I received this exception when executing a entitymanager.persist.

org.apache.openjpa.persistence.ArgumentException: Attempt to cast
instance "com.taxandtech.lab.faces.bean.Department@afa4b0" to
PersistenceCapable failed.  Ensure that it has been enhanced.

Why does this occur? How do I solve it? This same code works with
other persistency provider? What makes it different in OpenJPA?

This is my persistence.xml snippets:
    <persistence-unit name="openjpaPU">
    	<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    	<class>com.taxandtech.lab.faces.bean.Department</class>
    	<properties>
      		<property name="openjpa.ConnectionURL"
value="jdbc:mysql://localhost:3306/test"/>
      		<property name="openjpa.ConnectionDriverName"
value="com.mysql.jdbc.Driver"/>
      		<property name="openjpa.ConnectionUserName" value="joshua"/>
      		<property name="openjpa.ConnectionPassword" value="password"/>
      		<property name="openjpa.Log" value="DefaultLevel=INFO, Tool=INFO"/>
      		<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
    	</properties>
    </persistence-unit>

Thanks in advance

-- 
Let's create a highly maintainable and efficient code

YM!: thejavafreak
Blog: http://www.nagasakti.or.id/roller/joshua/

Re: Enhancing a persistent class

Posted by Patrick Linskey <pl...@gmail.com>.
> In JEE, the application server
> will generally handle the enhancement for you.

Generally-speaking, if you are using OpenJPA from Spring beans in a
Java EE environment, you should get deploy-time auto-enhancement.

Additionally, I wrote an IntelliJ plugin a little while back that
automatically processes your classes after compilation; if you're an
IntelliJ user, this can make things easier.

-Patrick

On 7/4/07, Michael Dick <mi...@gmail.com> wrote:
> Hi Joshua,
>
> The OpenJPA manual discusses the mechanisms in depth at
> http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance.
> In a nutshell :
>
> In order to track the state of an entity class OpenJPA inserts additional
> code into the entity class - which we refer to as enhancement.
>
> Inserting the additional code may be done at compile time (static
> enhancement) or during runtime (dynamic enhancement).
>
> Enhancing your entities at build time can be done by running the main method
> of org.apache.openjpa.enhance.PCEnhancer, or through the PCEnhancer ant
> task.
>
> Using dynamic enhancement in JSE can be done by specifying -javaagent:${path
> to openjpa.jar} when you run the application. In JEE, the application server
> will generally handle the enhancement for you.
>
> Hope this helps,
> -mike
>
>
> On 7/4/07, Joshua Jackson <jo...@gmail.com> wrote:
> >
> > Dear all,
> >
> > I received this exception when executing a entitymanager.persist.
> >
> > org.apache.openjpa.persistence.ArgumentException: Attempt to cast
> > instance "com.taxandtech.lab.faces.bean.Department@afa4b0" to
> > PersistenceCapable failed.  Ensure that it has been enhanced.
> >
> > Why does this occur? How do I solve it? This same code works with
> > other persistency provider? What makes it different in OpenJPA?
> >
> > This is my persistence.xml snippets:
> >     <persistence-unit name="openjpaPU">
> >         <provider>org.apache.openjpa.persistence.PersistenceProviderImpl
> > </provider>
> >         <class>com.taxandtech.lab.faces.bean.Department</class>
> >         <properties>
> >                 <property name="openjpa.ConnectionURL"
> > value="jdbc:mysql://localhost:3306/test"/>
> >                 <property name="openjpa.ConnectionDriverName"
> > value="com.mysql.jdbc.Driver"/>
> >                 <property name="openjpa.ConnectionUserName"
> > value="joshua"/>
> >                 <property name="openjpa.ConnectionPassword"
> > value="password"/>
> >                 <property name="openjpa.Log" value="DefaultLevel=INFO,
> > Tool=INFO"/>
> >                 <property name="openjpa.jdbc.SynchronizeMappings"
> > value="buildSchema(ForeignKeys=true)"/>
> >         </properties>
> >     </persistence-unit>
> >
> > Thanks in advance
> >
> > --
> > Let's create a highly maintainable and efficient code
> >
> > YM!: thejavafreak
> > Blog: http://www.nagasakti.or.id/roller/joshua/
> >
>


-- 
Patrick Linskey
202 669 5907

Re: Enhancing a persistent class

Posted by Michael Dick <mi...@gmail.com>.
Hi Joshua,

The OpenJPA manual discusses the mechanisms in depth at
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_pc_enhance.
In a nutshell :

In order to track the state of an entity class OpenJPA inserts additional
code into the entity class - which we refer to as enhancement.

Inserting the additional code may be done at compile time (static
enhancement) or during runtime (dynamic enhancement).

Enhancing your entities at build time can be done by running the main method
of org.apache.openjpa.enhance.PCEnhancer, or through the PCEnhancer ant
task.

Using dynamic enhancement in JSE can be done by specifying -javaagent:${path
to openjpa.jar} when you run the application. In JEE, the application server
will generally handle the enhancement for you.

Hope this helps,
-mike


On 7/4/07, Joshua Jackson <jo...@gmail.com> wrote:
>
> Dear all,
>
> I received this exception when executing a entitymanager.persist.
>
> org.apache.openjpa.persistence.ArgumentException: Attempt to cast
> instance "com.taxandtech.lab.faces.bean.Department@afa4b0" to
> PersistenceCapable failed.  Ensure that it has been enhanced.
>
> Why does this occur? How do I solve it? This same code works with
> other persistency provider? What makes it different in OpenJPA?
>
> This is my persistence.xml snippets:
>     <persistence-unit name="openjpaPU">
>         <provider>org.apache.openjpa.persistence.PersistenceProviderImpl
> </provider>
>         <class>com.taxandtech.lab.faces.bean.Department</class>
>         <properties>
>                 <property name="openjpa.ConnectionURL"
> value="jdbc:mysql://localhost:3306/test"/>
>                 <property name="openjpa.ConnectionDriverName"
> value="com.mysql.jdbc.Driver"/>
>                 <property name="openjpa.ConnectionUserName"
> value="joshua"/>
>                 <property name="openjpa.ConnectionPassword"
> value="password"/>
>                 <property name="openjpa.Log" value="DefaultLevel=INFO,
> Tool=INFO"/>
>                 <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)"/>
>         </properties>
>     </persistence-unit>
>
> Thanks in advance
>
> --
> Let's create a highly maintainable and efficient code
>
> YM!: thejavafreak
> Blog: http://www.nagasakti.or.id/roller/joshua/
>