You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Craig L Russell <Cr...@Sun.COM> on 2007/07/09 18:05:30 UTC

Re: Runtime Enhancement in Eclipse

Hi,

This is from the Java SE 6 documentation. It explains "all":
Command-Line Interface

On implementations with a command-line interface, an agent is started  
by adding this option to the command-line:

-javaagent:jarpath[=options]
jarpath is the path to the agent JAR file. options is the agent  
options. This switch may be used multiple times on the same command- 
line, thus creating multiple agents. More than one agent may use the  
same jarpath. An agent JAR file must conform to the JAR file  
specification.
The manifest of the agent JAR file must contain the attribute Premain- 
Class. The value of this attribute is the name of the agent class.  
The agent class must implement a public static premain method similar  
in principle to the main application entry point. After the Java  
Virtual Machine (JVM) has initialized, each premain method will be  
called in the order the agents were specified, then the real  
application main method will be called. Each premain method must  
return in order for the startup sequence to proceed.
The premain method has one of two possible signatures. The JVM first  
attempts to invoke the following method on the agent class:
public static void premain(String agentArgs, Instrumentation inst);
If the agent class does not implement this method then the JVM will  
attempt to invoke:

public static void premain(String agentArgs);
The agent class may also have an agentmain method for use when the  
agent is started after VM startup. When the agent is started using a  
command-line option, the agentmain method is not invoked.

The agent class will be loaded by the system class loader (see  
ClassLoader.getSystemClassLoader). This is the class loader which  
typically loads the class containing the application main method. The  
premain methods will be run under the same security and classloader  
rules as the application main method. There are no modeling  
restrictions on what the agent premain method may do. Anything  
application main can do, including creating threads, is legal from  
premain.

Each agent is passed its agent options via the agentArgs parameter.  
The agent options are passed as a single string, any additional  
parsing should be performed by the agent itself.

If the agent cannot be resolved (for example, because the agent class  
cannot be loaded, or because the agent class does not have an  
appropriate premain method), the JVM will abort. If a premain method  
throws an uncaught exception, the JVM will abort.



Craig


On Jul 9, 2007, at 8:51 AM, Janap wrote:

>
> Well..was just testing incase the newer version had some  
> undiscovered bugs.
>
> 2 more small things ...if I have read it correct syntax for  
> javaagent is...
>
> -javaagent myPackage.myClass
>
>
>
> Do i need any more arguments like path to persistence .xml or stuff,
>
> thx for the attention,
> best wishes
>
>
> Patrick Linskey-2 wrote:
>>
>> Not from me -- I'm not much of a javaagent expert.
>>
>> However, why are you moving backwards in time, rather than forwards,
>> with the version change?
>>
>> -Patrick
>>
>> On 7/9/07, Janap <ja...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> Thx for the tip. I added all the libraries to the classpath as  
>>> well and
>>> also
>>> replaced with 0.9.7 with 0.9.6 incubating libraries.
>>>
>>> Now the problem is :
>>>
>>> Error occurred during initialization of VM
>>> agent library failed to init: instrument
>>> Error opening zip file:
>>> C:\Programme\Eclipse\workspace\OpenJPATest\web\WEB-INF\lib 
>>> \openjpa-all-0.9.6-incubating.jar
>>>
>>> It seems that it cannot detect the jar file at all..i cross checked
>>> spellings and file location..any more suggestions?
>>>
>>>
>>>
>>> Patrick Linskey-2 wrote:
>>>>
>>>> Hi,
>>>>
>>>> You need to put OpenJPA's dependencies into the classpath as well.
>>>>
>>>> -Patrick
>>>>
>>>> On 7/9/07, Janap <ja...@gmail.com> wrote:
>>>>>
>>>>> Hello all,
>>>>>
>>>>> I am trying to run a simple Hello World OpenJPA application and  
>>>>> need
>>>>> enhancing to my classes.
>>>>> My application is now a dynamic web project in Eclipse.
>>>>>
>>>>> I want to add enhancing ability through the java agent.For this  
>>>>> in the
>>>>> Tomcat cofiguration i added..
>>>>>
>>>>>
>>> -javaagent:C:\Programme\Eclipse\workspace\OpenJPATest\web\WEB-INF 
>>> \lib\openjpa-0.9.7-incubating.jar
>>>>>  mypackage.myclass
>>>>>
>>>>> I get the following exception :
>>>>> Caused by: java.lang.NoClassDefFoundError:
>>>>> org/apache/commons/lang/exception/NestableRuntimeException
>>>>> Exception in thread "main" FATAL ERROR in native method:  
>>>>> processing of
>>>>> -javaagent failed
>>>>>
>>>>> Do I need to pass my persistent class as parameter or not...Can
>>> someone
>>>>> please point out my mistake.
>>>>>
>>>>> best wishes
>>>>> Jan
>>>>> --
>>>>> View this message in context:
>>>>>
>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse- 
>>> tf4049770.html#a11503057
>>>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Patrick Linskey
>>>> 202 669 5907
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse- 
>>> tf4049770.html#a11504139
>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>> -- 
>> Patrick Linskey
>> 202 669 5907
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Runtime- 
> Enhancement-in-Eclipse-tf4049770.html#a11504394
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.
Here is the source code for Scale.java

----------------------------------------------
package test;


import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Scale generated by hbm2java
 */
@Entity
@Table(name="SCALE"
)
public class Scale  implements java.io.Serializable {


     private long nscale;
     private String description;
     private Date dteingabe;

    public Scale() {
    }


    public Scale(long nscale) {
        this.nscale = nscale;
    }
    public Scale(long nscale, String description, Date dteingabe) {
       this.nscale = nscale;
       this.description = description;
       this.dteingabe = dteingabe;
    }

     @Id

    @Column(name="NSCALE", unique=true, nullable=false, precision=10,
scale=0)
    public long getNscale() {
        return this.nscale;
    }

    public void setNscale(long nscale) {
        this.nscale = nscale;
    }

    @Column(name="DESCRIPTION")
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Temporal(TemporalType.DATE)
    @Column(name="DTEINGABE", length=7)
    public Date getDteingabe() {
        return this.dteingabe;
    }

    public void setDteingabe(Date dteingabe) {
        this.dteingabe = dteingabe;
    }
}


----------------------------------------------




Janap wrote:
> 
> I have tried both the combinations Marc. I believe it might be a problem
> with my class. I have to post it tomorrow since I dont carry my work to
> home :-) The classes are entity classes which I have reverse engineered
> using the Hibernate Tools plugin for Eclipse. They are EJB 3.0 compatible
> and work fine with hibernate.
> 
> I appreciate the help,
> best wishes and good night
> Jan
> 
> 
> 
> 
> Marc Prud'hommeaux wrote:
>> 
>> 
>> 
>> I'm doubtful that this will help, but I do notice that your agent  
>> argument looks like:
>> 
>>    -javaagent:...,-scanDevPath=true,directory=...,-tmpClassLoader=false
>> 
>> Note that the "-" at the beginning of the parameters is probably  
>> causing them to be ignored. I think it needs to look like:
>> 
>>    -javaagent:...,scanDevPath=true,directory=...,tmpClassLoader=false
>> 
>> 
>> 
>> 
>> On Jul 11, 2007, at 2:27 AM, Janap wrote:
>> 
>>>
>>> Thx for the info Craig...got that step working. Didnt have time for  
>>> research
>>> for the past2 days,but now Im back with another problem.
>>>
>>> My web project structure is as follows..
>>>
>>> /build/classes/test/Scale.class
>>>
>>> /src/test/Scale.java
>>>
>>> /web/WEB-INF/classes/META-INF/persistence.xml
>>> /web/WEB-INF/classes/META-INF/orm.xml
>>>
>>> /web/WEB-INF/lib
>>>
>>> Following is my persistence.xml
>>>
>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"  
>>> version="1.0">
>>> <persistence-unit name="myPersistence"  transaction- 
>>> type="RESOURCE_LOCAL">
>>>         <provider>
>>>             org.apache.openjpa.persistence.PersistenceProviderImpl
>>>         </provider>
>>>         <mapping-file>orm.xml</mapping-file>
>>>         <class>test.Scale</class>
>>>         <properties>
>>>             <property name="openjpa.ConnectionURL" value="myurl"/>
>>>             <property name="openjpa.ConnectionDriverName"
>>> value="oracle.jdbc.driver.OracleDriver"/>
>>>             <property name="openjpa.ConnectionUserName"  
>>> value="myuser"/>
>>>             <property name="openjpa.ConnectionPassword"  
>>> value="mypwd"/>
>>>             <property name="openjpa.Log"
>>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>>>         </properties>
>>> </persistence-unit>
>>> </persistence>
>>>
>>>
>>>
>>> For runtime enhancement is start Tomcat within Eclipse with the  
>>> following VM
>>> arguments :
>>>
>>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib 
>>> \openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
>>> \classes\META-INF\persistence.xml,-scanDevPath=true,
>>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,- 
>>> tmpClassLoader=false
>>>
>>>
>>> My Tomcat starts properly with the following log :
>>>
>>> 15  TRACE  [main] openjpa.Runtime - Setting the following  
>>> properties from
>>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/ 
>>> classes/META-INF/persistence.xml"
>>> into configuration: {openjpa.ConnectionUserName=myuser,
>>> openjpa.ConnectionPassword=mypwd,  
>>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>>> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceP 
>>> roviderImpl,
>>> openjpa.ConnectionURL=myurl,
>>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata  
>>> in 0
>>> milliseconds.
>>>
>>>
>>> Then as I try to run this servlet code :
>>>
>>>     	EntityManagerFactory emf =
>>> Persistence.createEntityManagerFactory("myPersistence");
>>>
>>>     	EntityManager em = emf.createEntityManager();
>>>     	em.getTransaction().begin();
>>>
>>>     	Scale tab = new Scale(5);
>>>     	em.persist(tab);
>>>     	em.getTransaction().commit();
>>>     	em.close();
>>>     	emf.close();
>>>
>>> I run into an exception which I believe because my class is not  
>>> somehow
>>> enhanced :
>>>
>>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using  
>>> metadata factory
>>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8 
>>> ".
>>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using  
>>> dictionary
>>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1  
>>> classes with
>>> metadata in 16 milliseconds.
>>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
>>> requires runtime enhancement: true
>>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An  
>>> exception was
>>> thrown while attempting to perform class file transformation on
>>> "test/Scale":
>>> java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
>>> test.Scale
>>> 	at serp.util.Strings.toClass(Strings.java:211)
>>> 	at serp.util.Strings.toClass(Strings.java:140)
>>> 	at serp.bytecode.BCClass.getType(BCClass.java:565)
>>> 	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>> 	at
>>> org.apache.openjpa.enhance.PCClassFileTransformer.transform 
>>> (PCClassFileTransformer.java:124)
>>> 	at sun.instrument.TransformerManager.transform 
>>> (TransformerManager.java:122)
>>> 	at
>>> sun.instrument.InstrumentationImpl.transform 
>>> (InstrumentationImpl.java:155)
>>> 	at java.lang.ClassLoader.defineClass1(Native Method)
>>> 	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>>
>>>
>>> I tried out different combinations but was not  
>>> successful...probably someone
>>> could find the flaw..
>>>
>>> best wishes
>>> Jan
>>>
>>>
>>>
>>> Hi,
>>>
>>> This is from the Java SE 6 documentation. It explains "all":
>>> Command-Line Interface
>>>
>>> On implementations with a command-line interface, an agent is started
>>> by adding this option to the command-line:
>>>
>>> -javaagent:jarpath[=options]
>>> jarpath is the path to the agent JAR file. options is the agent
>>> options. This switch may be used multiple times on the same command-
>>> line, thus creating multiple agents. More than one agent may use the
>>> same jarpath. An agent JAR file must conform to the JAR file
>>> specification.
>>> The manifest of the agent JAR file must contain the attribute Premain-
>>> Class. The value of this attribute is the name of the agent class.
>>> The agent class must implement a public static premain method similar
>>> in principle to the main application entry point. After the Java
>>> Virtual Machine (JVM) has initialized, each premain method will be
>>> called in the order the agents were specified, then the real
>>> application main method will be called. Each premain method must
>>> return in order for the startup sequence to proceed.
>>> The premain method has one of two possible signatures. The JVM first
>>> attempts to invoke the following method on the agent class:
>>> public static void premain(String agentArgs, Instrumentation inst);
>>> If the agent class does not implement this method then the JVM will
>>> attempt to invoke:
>>>
>>> public static void premain(String agentArgs);
>>> The agent class may also have an agentmain method for use when the
>>> agent is started after VM startup. When the agent is started using a
>>> command-line option, the agentmain method is not invoked.
>>>
>>> The agent class will be loaded by the system class loader (see
>>> ClassLoader.getSystemClassLoader). This is the class loader which
>>> typically loads the class containing the application main method. The
>>> premain methods will be run under the same security and classloader
>>> rules as the application main method. There are no modeling
>>> restrictions on what the agent premain method may do. Anything
>>> application main can do, including creating threads, is legal from
>>> premain.
>>>
>>> Each agent is passed its agent options via the agentArgs parameter.
>>> The agent options are passed as a single string, any additional
>>> parsing should be performed by the agent itself.
>>>
>>> If the agent cannot be resolved (for example, because the agent class
>>> cannot be loaded, or because the agent class does not have an
>>> appropriate premain method), the JVM will abort. If a premain method
>>> throws an uncaught exception, the JVM will abort.
>>>
>>>
>>>
>>> Craig
>>>
>>>
>>>
>>> -- 
>>> View this message in context: http://www.nabble.com/Runtime- 
>>> Enhancement-in-Eclipse-tf4049770.html#a11537016
>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11556149
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.
I have tried both the combinations Marc. I believe it might be a problem with
my class. I have to post it tomorrow since I dont carry my work to home :-)
The classes are entity classes which I have reverse engineered using the
Hibernate Tools plugin for Eclipse. They are EJB 3.0 compatible and work
fine with hibernate.

I appreciate the help,
best wishes and good night
Jan




Marc Prud'hommeaux wrote:
> 
> 
> 
> I'm doubtful that this will help, but I do notice that your agent  
> argument looks like:
> 
>    -javaagent:...,-scanDevPath=true,directory=...,-tmpClassLoader=false
> 
> Note that the "-" at the beginning of the parameters is probably  
> causing them to be ignored. I think it needs to look like:
> 
>    -javaagent:...,scanDevPath=true,directory=...,tmpClassLoader=false
> 
> 
> 
> 
> On Jul 11, 2007, at 2:27 AM, Janap wrote:
> 
>>
>> Thx for the info Craig...got that step working. Didnt have time for  
>> research
>> for the past2 days,but now Im back with another problem.
>>
>> My web project structure is as follows..
>>
>> /build/classes/test/Scale.class
>>
>> /src/test/Scale.java
>>
>> /web/WEB-INF/classes/META-INF/persistence.xml
>> /web/WEB-INF/classes/META-INF/orm.xml
>>
>> /web/WEB-INF/lib
>>
>> Following is my persistence.xml
>>
>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"  
>> version="1.0">
>> <persistence-unit name="myPersistence"  transaction- 
>> type="RESOURCE_LOCAL">
>>         <provider>
>>             org.apache.openjpa.persistence.PersistenceProviderImpl
>>         </provider>
>>         <mapping-file>orm.xml</mapping-file>
>>         <class>test.Scale</class>
>>         <properties>
>>             <property name="openjpa.ConnectionURL" value="myurl"/>
>>             <property name="openjpa.ConnectionDriverName"
>> value="oracle.jdbc.driver.OracleDriver"/>
>>             <property name="openjpa.ConnectionUserName"  
>> value="myuser"/>
>>             <property name="openjpa.ConnectionPassword"  
>> value="mypwd"/>
>>             <property name="openjpa.Log"
>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>>         </properties>
>> </persistence-unit>
>> </persistence>
>>
>>
>>
>> For runtime enhancement is start Tomcat within Eclipse with the  
>> following VM
>> arguments :
>>
>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib 
>> \openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
>> \classes\META-INF\persistence.xml,-scanDevPath=true,
>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,- 
>> tmpClassLoader=false
>>
>>
>> My Tomcat starts properly with the following log :
>>
>> 15  TRACE  [main] openjpa.Runtime - Setting the following  
>> properties from
>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/ 
>> classes/META-INF/persistence.xml"
>> into configuration: {openjpa.ConnectionUserName=myuser,
>> openjpa.ConnectionPassword=mypwd,  
>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceP 
>> roviderImpl,
>> openjpa.ConnectionURL=myurl,
>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata  
>> in 0
>> milliseconds.
>>
>>
>> Then as I try to run this servlet code :
>>
>>     	EntityManagerFactory emf =
>> Persistence.createEntityManagerFactory("myPersistence");
>>
>>     	EntityManager em = emf.createEntityManager();
>>     	em.getTransaction().begin();
>>
>>     	Scale tab = new Scale(5);
>>     	em.persist(tab);
>>     	em.getTransaction().commit();
>>     	em.close();
>>     	emf.close();
>>
>> I run into an exception which I believe because my class is not  
>> somehow
>> enhanced :
>>
>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using  
>> metadata factory
>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8 
>> ".
>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using  
>> dictionary
>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1  
>> classes with
>> metadata in 16 milliseconds.
>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
>> requires runtime enhancement: true
>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An  
>> exception was
>> thrown while attempting to perform class file transformation on
>> "test/Scale":
>> java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
>> test.Scale
>> 	at serp.util.Strings.toClass(Strings.java:211)
>> 	at serp.util.Strings.toClass(Strings.java:140)
>> 	at serp.bytecode.BCClass.getType(BCClass.java:565)
>> 	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>> 	at
>> org.apache.openjpa.enhance.PCClassFileTransformer.transform 
>> (PCClassFileTransformer.java:124)
>> 	at sun.instrument.TransformerManager.transform 
>> (TransformerManager.java:122)
>> 	at
>> sun.instrument.InstrumentationImpl.transform 
>> (InstrumentationImpl.java:155)
>> 	at java.lang.ClassLoader.defineClass1(Native Method)
>> 	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>
>>
>> I tried out different combinations but was not  
>> successful...probably someone
>> could find the flaw..
>>
>> best wishes
>> Jan
>>
>>
>>
>> Hi,
>>
>> This is from the Java SE 6 documentation. It explains "all":
>> Command-Line Interface
>>
>> On implementations with a command-line interface, an agent is started
>> by adding this option to the command-line:
>>
>> -javaagent:jarpath[=options]
>> jarpath is the path to the agent JAR file. options is the agent
>> options. This switch may be used multiple times on the same command-
>> line, thus creating multiple agents. More than one agent may use the
>> same jarpath. An agent JAR file must conform to the JAR file
>> specification.
>> The manifest of the agent JAR file must contain the attribute Premain-
>> Class. The value of this attribute is the name of the agent class.
>> The agent class must implement a public static premain method similar
>> in principle to the main application entry point. After the Java
>> Virtual Machine (JVM) has initialized, each premain method will be
>> called in the order the agents were specified, then the real
>> application main method will be called. Each premain method must
>> return in order for the startup sequence to proceed.
>> The premain method has one of two possible signatures. The JVM first
>> attempts to invoke the following method on the agent class:
>> public static void premain(String agentArgs, Instrumentation inst);
>> If the agent class does not implement this method then the JVM will
>> attempt to invoke:
>>
>> public static void premain(String agentArgs);
>> The agent class may also have an agentmain method for use when the
>> agent is started after VM startup. When the agent is started using a
>> command-line option, the agentmain method is not invoked.
>>
>> The agent class will be loaded by the system class loader (see
>> ClassLoader.getSystemClassLoader). This is the class loader which
>> typically loads the class containing the application main method. The
>> premain methods will be run under the same security and classloader
>> rules as the application main method. There are no modeling
>> restrictions on what the agent premain method may do. Anything
>> application main can do, including creating threads, is legal from
>> premain.
>>
>> Each agent is passed its agent options via the agentArgs parameter.
>> The agent options are passed as a single string, any additional
>> parsing should be performed by the agent itself.
>>
>> If the agent cannot be resolved (for example, because the agent class
>> cannot be loaded, or because the agent class does not have an
>> appropriate premain method), the JVM will abort. If a premain method
>> throws an uncaught exception, the JVM will abort.
>>
>>
>>
>> Craig
>>
>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Runtime- 
>> Enhancement-in-Eclipse-tf4049770.html#a11537016
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11547982
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Runtime Enhancement in Eclipse

Posted by Marc Prud'hommeaux <mp...@apache.org>.

I'm doubtful that this will help, but I do notice that your agent  
argument looks like:

   -javaagent:...,-scanDevPath=true,directory=...,-tmpClassLoader=false

Note that the "-" at the beginning of the parameters is probably  
causing them to be ignored. I think it needs to look like:

   -javaagent:...,scanDevPath=true,directory=...,tmpClassLoader=false




On Jul 11, 2007, at 2:27 AM, Janap wrote:

>
> Thx for the info Craig...got that step working. Didnt have time for  
> research
> for the past2 days,but now Im back with another problem.
>
> My web project structure is as follows..
>
> /build/classes/test/Scale.class
>
> /src/test/Scale.java
>
> /web/WEB-INF/classes/META-INF/persistence.xml
> /web/WEB-INF/classes/META-INF/orm.xml
>
> /web/WEB-INF/lib
>
> Following is my persistence.xml
>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"  
> version="1.0">
> <persistence-unit name="myPersistence"  transaction- 
> type="RESOURCE_LOCAL">
>         <provider>
>             org.apache.openjpa.persistence.PersistenceProviderImpl
>         </provider>
>         <mapping-file>orm.xml</mapping-file>
>         <class>test.Scale</class>
>         <properties>
>             <property name="openjpa.ConnectionURL" value="myurl"/>
>             <property name="openjpa.ConnectionDriverName"
> value="oracle.jdbc.driver.OracleDriver"/>
>             <property name="openjpa.ConnectionUserName"  
> value="myuser"/>
>             <property name="openjpa.ConnectionPassword"  
> value="mypwd"/>
>             <property name="openjpa.Log"
> value="DefaultLevel=TRACE,Tool=TRACE"/>
>         </properties>
> </persistence-unit>
> </persistence>
>
>
>
> For runtime enhancement is start Tomcat within Eclipse with the  
> following VM
> arguments :
>
> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib 
> \openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
> \classes\META-INF\persistence.xml,-scanDevPath=true,
> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,- 
> tmpClassLoader=false
>
>
> My Tomcat starts properly with the following log :
>
> 15  TRACE  [main] openjpa.Runtime - Setting the following  
> properties from
> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/ 
> classes/META-INF/persistence.xml"
> into configuration: {openjpa.ConnectionUserName=myuser,
> openjpa.ConnectionPassword=mypwd,  
> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceP 
> roviderImpl,
> openjpa.ConnectionURL=myurl,
> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
> 186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata  
> in 0
> milliseconds.
>
>
> Then as I try to run this servlet code :
>
>     	EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("myPersistence");
>
>     	EntityManager em = emf.createEntityManager();
>     	em.getTransaction().begin();
>
>     	Scale tab = new Scale(5);
>     	em.persist(tab);
>     	em.getTransaction().commit();
>     	em.close();
>     	emf.close();
>
> I run into an exception which I believe because my class is not  
> somehow
> enhanced :
>
> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using  
> metadata factory
> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8 
> ".
> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using  
> dictionary
> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1  
> classes with
> metadata in 16 milliseconds.
> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
> requires runtime enhancement: true
> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An  
> exception was
> thrown while attempting to perform class file transformation on
> "test/Scale":
> java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
> test.Scale
> 	at serp.util.Strings.toClass(Strings.java:211)
> 	at serp.util.Strings.toClass(Strings.java:140)
> 	at serp.bytecode.BCClass.getType(BCClass.java:565)
> 	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
> 	at
> org.apache.openjpa.enhance.PCClassFileTransformer.transform 
> (PCClassFileTransformer.java:124)
> 	at sun.instrument.TransformerManager.transform 
> (TransformerManager.java:122)
> 	at
> sun.instrument.InstrumentationImpl.transform 
> (InstrumentationImpl.java:155)
> 	at java.lang.ClassLoader.defineClass1(Native Method)
> 	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>
>
> I tried out different combinations but was not  
> successful...probably someone
> could find the flaw..
>
> best wishes
> Jan
>
>
>
> Hi,
>
> This is from the Java SE 6 documentation. It explains "all":
> Command-Line Interface
>
> On implementations with a command-line interface, an agent is started
> by adding this option to the command-line:
>
> -javaagent:jarpath[=options]
> jarpath is the path to the agent JAR file. options is the agent
> options. This switch may be used multiple times on the same command-
> line, thus creating multiple agents. More than one agent may use the
> same jarpath. An agent JAR file must conform to the JAR file
> specification.
> The manifest of the agent JAR file must contain the attribute Premain-
> Class. The value of this attribute is the name of the agent class.
> The agent class must implement a public static premain method similar
> in principle to the main application entry point. After the Java
> Virtual Machine (JVM) has initialized, each premain method will be
> called in the order the agents were specified, then the real
> application main method will be called. Each premain method must
> return in order for the startup sequence to proceed.
> The premain method has one of two possible signatures. The JVM first
> attempts to invoke the following method on the agent class:
> public static void premain(String agentArgs, Instrumentation inst);
> If the agent class does not implement this method then the JVM will
> attempt to invoke:
>
> public static void premain(String agentArgs);
> The agent class may also have an agentmain method for use when the
> agent is started after VM startup. When the agent is started using a
> command-line option, the agentmain method is not invoked.
>
> The agent class will be loaded by the system class loader (see
> ClassLoader.getSystemClassLoader). This is the class loader which
> typically loads the class containing the application main method. The
> premain methods will be run under the same security and classloader
> rules as the application main method. There are no modeling
> restrictions on what the agent premain method may do. Anything
> application main can do, including creating threads, is legal from
> premain.
>
> Each agent is passed its agent options via the agentArgs parameter.
> The agent options are passed as a single string, any additional
> parsing should be performed by the agent itself.
>
> If the agent cannot be resolved (for example, because the agent class
> cannot be loaded, or because the agent class does not have an
> appropriate premain method), the JVM will abort. If a premain method
> throws an uncaught exception, the JVM will abort.
>
>
>
> Craig
>
>
>
> -- 
> View this message in context: http://www.nabble.com/Runtime- 
> Enhancement-in-Eclipse-tf4049770.html#a11537016
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>


Re: Runtime Enhancement in Eclipse

Posted by Craig L Russell <Cr...@Sun.COM>.
It does sound like the Europa could use an update to avoid generating  
BigDecimal.

By the way, BigInteger does not have the same issue w.r.t. equals vs.  
compareTo that BigDecimal has. The only issue that I know of with  
BigInteger is its nullability, which means it's an inexact mapping to  
primary key columns that must be non-null.

If you're mapping from a primary key column with a size less than 9  
I'd definitely want to have it mapped to long.

Craig

On Jul 13, 2007, at 9:28 AM, Thierry Lach wrote:

> In light of the comments about BigDecimal inconsistencies, I think I'd
> consider that to be a flaw in the JPA Eclipse Plugin.
>
> On 7/12/07, Janap <ja...@gmail.com> wrote:
>>
>>
>> HI Craig,
>>
>> Thank you for the tip. But its surprising that when I generate Entity
>> classes using the JPA Eclipse Plugin(from Europa) the default type it
>> assigns is BigDecimal.  Changing for one class is no problem but
>> when I generate classes for a complete database , it might require  
>> some
>> refactoring I believe.
>>
>> Jan
>>
>>
>> Craig L Russell wrote:
>> >
>> > Hi Janap,
>> >
>> > I'd recommend you stay far away from BigDecimal fields for primary
>> > keys, even if your provider supports them.
>> >
>> > The BigDecimal class has a strange notion of equality that makes it
>> > unsuitable for primary keys. That is, given BigDecimal instances A
>> > and B, the following can be true:
>> >
>> > (0 == A .compareTo B) true
>> > (A .equals B) false
>> >
>> > This means that using BigDecimal instances as keys in Maps is
>> > impossible. Well, really hard.
>> >
>> > The JPA spec requires support for float and double types but  
>> strongly
>> > discourages their use. BigDecimal isn't even required due to these
>> > problems.
>> >
>> > Craig
>> >
>> > On Jul 12, 2007, at 9:56 AM, Janap wrote:
>> >
>> >>
>> >> Whoa....Enhancement works finally. I gave up the javaagent,fiddled
>> >> around
>> >> with the Enhancer Task which all said the same thing .....
>> >>
>> >>  [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1  
>> classes with
>> >> metadata in 0 milliseconds.
>> >>  [openjpac] 141  INFO   [main] openjpa.MetaData - The class
>> >> "test.Scale"
>> >> listed in the openjpa.MetaDataFactory configuration property could
>> >> not be
>> >> loaded; ignoring.
>> >>
>> >> i compiled it with the PCEnhancer java class. In Eclipse it is  
>> just
>> >> a click
>> >> away.
>> >>
>> >> One more observation - I now am using the JPA Eclipse Plugin to
>> >> generate
>> >> Entity classes and then enhance them. During this process, the
>> >> enhancer once
>> >> complained that I cannot use "BigDecimal" as primary key.
>> >> The enhancement worked after I converted it to "long". Any ideas?
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> Janap wrote:
>> >>>
>> >>> I have tried both the combinations Marc. I believe it might be a
>> >>> problem
>> >>> with my class. I have to post the source tomorrow since I dont
>> >>> carry my
>> >>> work to home :-) The classes are entity classes which I have  
>> reverse
>> >>> engineered using the Hibernate Tools plugin for Eclipse. They are
>> >>> EJB 3.0
>> >>> compatible and work fine with hibernate.
>> >>>
>> >>> I appreciate the help,
>> >>> best wishes and good night
>> >>> Jan
>> >>>
>> >>>
>> >>> Patrick Linskey-2 wrote:
>> >>>>
>> >>>> Can you post the source to the Scale class?
>> >>>>
>> >>>> -Patrick
>> >>>>
>> >>>> On 7/11/07, Janap <ja...@gmail.com> wrote:
>> >>>>>
>> >>>>> Thx for the info Craig...got that step working. Didnt have  
>> time for
>> >>>>> research
>> >>>>> for the past2 days,but now Im back with another problem.
>> >>>>>
>> >>>>> My web project structure is as follows..
>> >>>>>
>> >>>>> /build/classes/test/Scale.class
>> >>>>>
>> >>>>> /src/test/Scale.java
>> >>>>>
>> >>>>> /web/WEB-INF/classes/META-INF/persistence.xml
>> >>>>> /web/WEB-INF/classes/META-INF/orm.xml
>> >>>>>
>> >>>>> /web/WEB-INF/lib
>> >>>>>
>> >>>>> Following is my persistence.xml
>> >>>>>
>> >>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>> >>>>> version="1.0">
>> >>>>> <persistence-unit name="myPersistence"
>> >>>>> transaction-type="RESOURCE_LOCAL">
>> >>>>>         <provider>
>> >>>>>              
>> org.apache.openjpa.persistence.PersistenceProviderImpl
>> >>>>>         </provider>
>> >>>>>         <mapping-file>orm.xml</mapping-file>
>> >>>>>         <class>test.Scale</class>
>> >>>>>         <properties>
>> >>>>>             <property name="openjpa.ConnectionURL"  
>> value="myurl"/>
>> >>>>>             <property name="openjpa.ConnectionDriverName"
>> >>>>> value="oracle.jdbc.driver.OracleDriver"/>
>> >>>>>             <property name="openjpa.ConnectionUserName"
>> >>>>> value="myuser"/>
>> >>>>>             <property name="openjpa.ConnectionPassword"
>> >>>>> value="mypwd"/>
>> >>>>>             <property name="openjpa.Log"
>> >>>>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>> >>>>>         </properties>
>> >>>>> </persistence-unit>
>> >>>>> </persistence>
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> For runtime enhancement is start Tomcat within Eclipse with the
>> >>>>> following VM
>> >>>>> arguments :
>> >>>>>
>> >>>>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB- 
>> INF
>> >>>>> \lib\openjpa-all-0.9.6- 
>> incubating.jar=addDefaultConstructor=false
>> >>>>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web 
>> \WEB-INF
>> >>>>> \classes\META-INF\persistence.xml,-scanDevPath=true,
>> >>>>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build
>> >>>>> \classes,-tmpClassLoader=false
>> >>>>>
>> >>>>>
>> >>>>> My Tomcat starts properly with the following log :
>> >>>>>
>> >>>>> 15  TRACE  [main] openjpa.Runtime - Setting the following
>> >>>>> properties
>> >>>>> from
>> >>>>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/
>> >>>>> classes/META-INF/persistence.xml"
>> >>>>> into configuration: {openjpa.ConnectionUserName=myuser,
>> >>>>> openjpa.ConnectionPassword=mypwd,
>> >>>>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>> >>>>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>> >>>>>  
>> javax.persistence.provider=org.apache.openjpa.persistence.Persisten
>> >>>>> ceProviderImpl,
>> >>>>> openjpa.ConnectionURL=myurl,
>> >>>>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>> >>>>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with
>> >>>>> metadata in 0
>> >>>>> milliseconds.
>> >>>>>
>> >>>>>
>> >>>>> Then as I try to run this servlet code :
>> >>>>>
>> >>>>>         EntityManagerFactory emf =
>> >>>>> Persistence.createEntityManagerFactory("myPersistence");
>> >>>>>
>> >>>>>         EntityManager em = emf.createEntityManager();
>> >>>>>         em.getTransaction().begin();
>> >>>>>
>> >>>>>         Scale tab = new Scale(5);
>> >>>>>         em.persist(tab);
>> >>>>>         em.getTransaction().commit();
>> >>>>>         em.close();
>> >>>>>         emf.close();
>> >>>>>
>> >>>>> I run into an exception which I believe because my class is not
>> >>>>> somehow
>> >>>>> enhanced :
>> >>>>>
>> >>>>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using
>> >>>>> metadata
>> >>>>> factory
>> >>>>>  
>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0b
>> >>>>> dc8".
>> >>>>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using
>> >>>>> dictionary
>> >>>>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>> >>>>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1
>> >>>>> classes
>> >>>>> with
>> >>>>> metadata in 16 milliseconds.
>> >>>>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/
>> >>>>> Scale"
>> >>>>> requires runtime enhancement: true
>> >>>>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An
>> >>>>> exception was
>> >>>>> thrown while attempting to perform class file transformation on
>> >>>>> "test/Scale":
>> >>>>> java.lang.IllegalArgumentException:
>> >>>>> java.lang.ClassNotFoundException:
>> >>>>> test.Scale
>> >>>>>         at serp.util.Strings.toClass(Strings.java:211)
>> >>>>>         at serp.util.Strings.toClass(Strings.java:140)
>> >>>>>         at serp.bytecode.BCClass.getType(BCClass.java:565)
>> >>>>>         at
>> >>>>> org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java: 
>> 187)
>> >>>>>         at
>> >>>>> org.apache.openjpa.enhance.PCClassFileTransformer.transform
>> >>>>> (PCClassFileTransformer.java:124)
>> >>>>>         at
>> >>>>> sun.instrument.TransformerManager.transform
>> >>>>> (TransformerManager.java:122)
>> >>>>>         at
>> >>>>> sun.instrument.InstrumentationImpl.transform
>> >>>>> (InstrumentationImpl.java:155)
>> >>>>>         at java.lang.ClassLoader.defineClass1(Native Method)
>> >>>>>         at java.lang.ClassLoader.defineClass 
>> (ClassLoader.java:620)
>> >>>>>
>> >>>>>
>> >>>>> I tried out different combinations but was not
>> >>>>> successful...probably
>> >>>>> someone
>> >>>>> could find the flaw..
>> >>>>>
>> >>>>> best wishes
>> >>>>> Jan
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> Hi,
>> >>>>>
>> >>>>> This is from the Java SE 6 documentation. It explains "all":
>> >>>>> Command-Line Interface
>> >>>>>
>> >>>>> On implementations with a command-line interface, an agent is
>> >>>>> started
>> >>>>> by adding this option to the command-line:
>> >>>>>
>> >>>>> -javaagent:jarpath[=options]
>> >>>>> jarpath is the path to the agent JAR file. options is the agent
>> >>>>> options. This switch may be used multiple times on the same
>> >>>>> command-
>> >>>>> line, thus creating multiple agents. More than one agent may  
>> use
>> >>>>> the
>> >>>>> same jarpath. An agent JAR file must conform to the JAR file
>> >>>>> specification.
>> >>>>> The manifest of the agent JAR file must contain the attribute
>> >>>>> Premain-
>> >>>>> Class. The value of this attribute is the name of the agent  
>> class.
>> >>>>> The agent class must implement a public static premain method
>> >>>>> similar
>> >>>>> in principle to the main application entry point. After the  
>> Java
>> >>>>> Virtual Machine (JVM) has initialized, each premain method  
>> will be
>> >>>>> called in the order the agents were specified, then the real
>> >>>>> application main method will be called. Each premain method  
>> must
>> >>>>> return in order for the startup sequence to proceed.
>> >>>>> The premain method has one of two possible signatures. The JVM
>> >>>>> first
>> >>>>> attempts to invoke the following method on the agent class:
>> >>>>> public static void premain(String agentArgs, Instrumentation  
>> inst);
>> >>>>> If the agent class does not implement this method then the  
>> JVM will
>> >>>>> attempt to invoke:
>> >>>>>
>> >>>>> public static void premain(String agentArgs);
>> >>>>> The agent class may also have an agentmain method for use  
>> when the
>> >>>>> agent is started after VM startup. When the agent is started
>> >>>>> using a
>> >>>>> command-line option, the agentmain method is not invoked.
>> >>>>>
>> >>>>> The agent class will be loaded by the system class loader (see
>> >>>>> ClassLoader.getSystemClassLoader). This is the class loader  
>> which
>> >>>>> typically loads the class containing the application main
>> >>>>> method. The
>> >>>>> premain methods will be run under the same security and  
>> classloader
>> >>>>> rules as the application main method. There are no modeling
>> >>>>> restrictions on what the agent premain method may do. Anything
>> >>>>> application main can do, including creating threads, is  
>> legal from
>> >>>>> premain.
>> >>>>>
>> >>>>> Each agent is passed its agent options via the agentArgs  
>> parameter.
>> >>>>> The agent options are passed as a single string, any additional
>> >>>>> parsing should be performed by the agent itself.
>> >>>>>
>> >>>>> If the agent cannot be resolved (for example, because the agent
>> >>>>> class
>> >>>>> cannot be loaded, or because the agent class does not have an
>> >>>>> appropriate premain method), the JVM will abort. If a premain
>> >>>>> method
>> >>>>> throws an uncaught exception, the JVM will abort.
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> Craig
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> View this message in context:
>> >>>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse-
>> >>>>> tf4049770.html#a11537016
>> >>>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> >>>>>
>> >>>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Patrick Linskey
>> >>>> 202 669 5907
>> >>>>
>> >>>>
>> >>>
>> >>>
>> >>
>> >> --
>> >> View this message in context: http://www.nabble.com/Runtime-
>> >> Enhancement-in-Eclipse-tf4049770.html#a11564182
>> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>> >>
>> >
>> > Craig Russell
>> > Architect, Sun Java Enterprise System http://java.sun.com/ 
>> products/jdo
>> > 408 276-5638 mailto:Craig.Russell@sun.com
>> > P.S. A good JDO? O, Gasp!
>> >
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse- 
>> tf4049770.html#a11565895
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Runtime Enhancement in Eclipse

Posted by Thierry Lach <th...@gmail.com>.
In light of the comments about BigDecimal inconsistencies, I think I'd
consider that to be a flaw in the JPA Eclipse Plugin.

On 7/12/07, Janap <ja...@gmail.com> wrote:
>
>
> HI Craig,
>
> Thank you for the tip. But its surprising that when I generate Entity
> classes using the JPA Eclipse Plugin(from Europa) the default type it
> assigns is BigDecimal.  Changing for one class is no problem but
> when I generate classes for a complete database , it might require some
> refactoring I believe.
>
> Jan
>
>
> Craig L Russell wrote:
> >
> > Hi Janap,
> >
> > I'd recommend you stay far away from BigDecimal fields for primary
> > keys, even if your provider supports them.
> >
> > The BigDecimal class has a strange notion of equality that makes it
> > unsuitable for primary keys. That is, given BigDecimal instances A
> > and B, the following can be true:
> >
> > (0 == A .compareTo B) true
> > (A .equals B) false
> >
> > This means that using BigDecimal instances as keys in Maps is
> > impossible. Well, really hard.
> >
> > The JPA spec requires support for float and double types but strongly
> > discourages their use. BigDecimal isn't even required due to these
> > problems.
> >
> > Craig
> >
> > On Jul 12, 2007, at 9:56 AM, Janap wrote:
> >
> >>
> >> Whoa....Enhancement works finally. I gave up the javaagent,fiddled
> >> around
> >> with the Enhancer Task which all said the same thing .....
> >>
> >>  [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1 classes with
> >> metadata in 0 milliseconds.
> >>  [openjpac] 141  INFO   [main] openjpa.MetaData - The class
> >> "test.Scale"
> >> listed in the openjpa.MetaDataFactory configuration property could
> >> not be
> >> loaded; ignoring.
> >>
> >> i compiled it with the PCEnhancer java class. In Eclipse it is just
> >> a click
> >> away.
> >>
> >> One more observation - I now am using the JPA Eclipse Plugin to
> >> generate
> >> Entity classes and then enhance them. During this process, the
> >> enhancer once
> >> complained that I cannot use "BigDecimal" as primary key.
> >> The enhancement worked after I converted it to "long". Any ideas?
> >>
> >>
> >>
> >>
> >>
> >> Janap wrote:
> >>>
> >>> I have tried both the combinations Marc. I believe it might be a
> >>> problem
> >>> with my class. I have to post the source tomorrow since I dont
> >>> carry my
> >>> work to home :-) The classes are entity classes which I have reverse
> >>> engineered using the Hibernate Tools plugin for Eclipse. They are
> >>> EJB 3.0
> >>> compatible and work fine with hibernate.
> >>>
> >>> I appreciate the help,
> >>> best wishes and good night
> >>> Jan
> >>>
> >>>
> >>> Patrick Linskey-2 wrote:
> >>>>
> >>>> Can you post the source to the Scale class?
> >>>>
> >>>> -Patrick
> >>>>
> >>>> On 7/11/07, Janap <ja...@gmail.com> wrote:
> >>>>>
> >>>>> Thx for the info Craig...got that step working. Didnt have time for
> >>>>> research
> >>>>> for the past2 days,but now Im back with another problem.
> >>>>>
> >>>>> My web project structure is as follows..
> >>>>>
> >>>>> /build/classes/test/Scale.class
> >>>>>
> >>>>> /src/test/Scale.java
> >>>>>
> >>>>> /web/WEB-INF/classes/META-INF/persistence.xml
> >>>>> /web/WEB-INF/classes/META-INF/orm.xml
> >>>>>
> >>>>> /web/WEB-INF/lib
> >>>>>
> >>>>> Following is my persistence.xml
> >>>>>
> >>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> >>>>> version="1.0">
> >>>>> <persistence-unit name="myPersistence"
> >>>>> transaction-type="RESOURCE_LOCAL">
> >>>>>         <provider>
> >>>>>             org.apache.openjpa.persistence.PersistenceProviderImpl
> >>>>>         </provider>
> >>>>>         <mapping-file>orm.xml</mapping-file>
> >>>>>         <class>test.Scale</class>
> >>>>>         <properties>
> >>>>>             <property name="openjpa.ConnectionURL" value="myurl"/>
> >>>>>             <property name="openjpa.ConnectionDriverName"
> >>>>> value="oracle.jdbc.driver.OracleDriver"/>
> >>>>>             <property name="openjpa.ConnectionUserName"
> >>>>> value="myuser"/>
> >>>>>             <property name="openjpa.ConnectionPassword"
> >>>>> value="mypwd"/>
> >>>>>             <property name="openjpa.Log"
> >>>>> value="DefaultLevel=TRACE,Tool=TRACE"/>
> >>>>>         </properties>
> >>>>> </persistence-unit>
> >>>>> </persistence>
> >>>>>
> >>>>>
> >>>>>
> >>>>> For runtime enhancement is start Tomcat within Eclipse with the
> >>>>> following VM
> >>>>> arguments :
> >>>>>
> >>>>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF
> >>>>> \lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
> >>>>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF
> >>>>> \classes\META-INF\persistence.xml,-scanDevPath=true,
> >>>>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build
> >>>>> \classes,-tmpClassLoader=false
> >>>>>
> >>>>>
> >>>>> My Tomcat starts properly with the following log :
> >>>>>
> >>>>> 15  TRACE  [main] openjpa.Runtime - Setting the following
> >>>>> properties
> >>>>> from
> >>>>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/
> >>>>> classes/META-INF/persistence.xml"
> >>>>> into configuration: {openjpa.ConnectionUserName=myuser,
> >>>>> openjpa.ConnectionPassword=mypwd,
> >>>>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
> >>>>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
> >>>>> javax.persistence.provider=org.apache.openjpa.persistence.Persisten
> >>>>> ceProviderImpl,
> >>>>> openjpa.ConnectionURL=myurl,
> >>>>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
> >>>>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with
> >>>>> metadata in 0
> >>>>> milliseconds.
> >>>>>
> >>>>>
> >>>>> Then as I try to run this servlet code :
> >>>>>
> >>>>>         EntityManagerFactory emf =
> >>>>> Persistence.createEntityManagerFactory("myPersistence");
> >>>>>
> >>>>>         EntityManager em = emf.createEntityManager();
> >>>>>         em.getTransaction().begin();
> >>>>>
> >>>>>         Scale tab = new Scale(5);
> >>>>>         em.persist(tab);
> >>>>>         em.getTransaction().commit();
> >>>>>         em.close();
> >>>>>         emf.close();
> >>>>>
> >>>>> I run into an exception which I believe because my class is not
> >>>>> somehow
> >>>>> enhanced :
> >>>>>
> >>>>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using
> >>>>> metadata
> >>>>> factory
> >>>>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0b
> >>>>> dc8".
> >>>>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using
> >>>>> dictionary
> >>>>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
> >>>>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1
> >>>>> classes
> >>>>> with
> >>>>> metadata in 16 milliseconds.
> >>>>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/
> >>>>> Scale"
> >>>>> requires runtime enhancement: true
> >>>>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An
> >>>>> exception was
> >>>>> thrown while attempting to perform class file transformation on
> >>>>> "test/Scale":
> >>>>> java.lang.IllegalArgumentException:
> >>>>> java.lang.ClassNotFoundException:
> >>>>> test.Scale
> >>>>>         at serp.util.Strings.toClass(Strings.java:211)
> >>>>>         at serp.util.Strings.toClass(Strings.java:140)
> >>>>>         at serp.bytecode.BCClass.getType(BCClass.java:565)
> >>>>>         at
> >>>>> org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
> >>>>>         at
> >>>>> org.apache.openjpa.enhance.PCClassFileTransformer.transform
> >>>>> (PCClassFileTransformer.java:124)
> >>>>>         at
> >>>>> sun.instrument.TransformerManager.transform
> >>>>> (TransformerManager.java:122)
> >>>>>         at
> >>>>> sun.instrument.InstrumentationImpl.transform
> >>>>> (InstrumentationImpl.java:155)
> >>>>>         at java.lang.ClassLoader.defineClass1(Native Method)
> >>>>>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
> >>>>>
> >>>>>
> >>>>> I tried out different combinations but was not
> >>>>> successful...probably
> >>>>> someone
> >>>>> could find the flaw..
> >>>>>
> >>>>> best wishes
> >>>>> Jan
> >>>>>
> >>>>>
> >>>>>
> >>>>> Hi,
> >>>>>
> >>>>> This is from the Java SE 6 documentation. It explains "all":
> >>>>> Command-Line Interface
> >>>>>
> >>>>> On implementations with a command-line interface, an agent is
> >>>>> started
> >>>>> by adding this option to the command-line:
> >>>>>
> >>>>> -javaagent:jarpath[=options]
> >>>>> jarpath is the path to the agent JAR file. options is the agent
> >>>>> options. This switch may be used multiple times on the same
> >>>>> command-
> >>>>> line, thus creating multiple agents. More than one agent may use
> >>>>> the
> >>>>> same jarpath. An agent JAR file must conform to the JAR file
> >>>>> specification.
> >>>>> The manifest of the agent JAR file must contain the attribute
> >>>>> Premain-
> >>>>> Class. The value of this attribute is the name of the agent class.
> >>>>> The agent class must implement a public static premain method
> >>>>> similar
> >>>>> in principle to the main application entry point. After the Java
> >>>>> Virtual Machine (JVM) has initialized, each premain method will be
> >>>>> called in the order the agents were specified, then the real
> >>>>> application main method will be called. Each premain method must
> >>>>> return in order for the startup sequence to proceed.
> >>>>> The premain method has one of two possible signatures. The JVM
> >>>>> first
> >>>>> attempts to invoke the following method on the agent class:
> >>>>> public static void premain(String agentArgs, Instrumentation inst);
> >>>>> If the agent class does not implement this method then the JVM will
> >>>>> attempt to invoke:
> >>>>>
> >>>>> public static void premain(String agentArgs);
> >>>>> The agent class may also have an agentmain method for use when the
> >>>>> agent is started after VM startup. When the agent is started
> >>>>> using a
> >>>>> command-line option, the agentmain method is not invoked.
> >>>>>
> >>>>> The agent class will be loaded by the system class loader (see
> >>>>> ClassLoader.getSystemClassLoader). This is the class loader which
> >>>>> typically loads the class containing the application main
> >>>>> method. The
> >>>>> premain methods will be run under the same security and classloader
> >>>>> rules as the application main method. There are no modeling
> >>>>> restrictions on what the agent premain method may do. Anything
> >>>>> application main can do, including creating threads, is legal from
> >>>>> premain.
> >>>>>
> >>>>> Each agent is passed its agent options via the agentArgs parameter.
> >>>>> The agent options are passed as a single string, any additional
> >>>>> parsing should be performed by the agent itself.
> >>>>>
> >>>>> If the agent cannot be resolved (for example, because the agent
> >>>>> class
> >>>>> cannot be loaded, or because the agent class does not have an
> >>>>> appropriate premain method), the JVM will abort. If a premain
> >>>>> method
> >>>>> throws an uncaught exception, the JVM will abort.
> >>>>>
> >>>>>
> >>>>>
> >>>>> Craig
> >>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> View this message in context:
> >>>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse-
> >>>>> tf4049770.html#a11537016
> >>>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>> --
> >>>> Patrick Linskey
> >>>> 202 669 5907
> >>>>
> >>>>
> >>>
> >>>
> >>
> >> --
> >> View this message in context: http://www.nabble.com/Runtime-
> >> Enhancement-in-Eclipse-tf4049770.html#a11564182
> >> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> >>
> >
> > Craig Russell
> > Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> > 408 276-5638 mailto:Craig.Russell@sun.com
> > P.S. A good JDO? O, Gasp!
> >
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11565895
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.
HI Craig,

Thank you for the tip. But its surprising that when I generate Entity
classes using the JPA Eclipse Plugin(from Europa) the default type it
assigns is BigDecimal.  Changing for one class is no problem but 
when I generate classes for a complete database , it might require some
refactoring I believe.

Jan


Craig L Russell wrote:
> 
> Hi Janap,
> 
> I'd recommend you stay far away from BigDecimal fields for primary  
> keys, even if your provider supports them.
> 
> The BigDecimal class has a strange notion of equality that makes it  
> unsuitable for primary keys. That is, given BigDecimal instances A  
> and B, the following can be true:
> 
> (0 == A .compareTo B) true
> (A .equals B) false
> 
> This means that using BigDecimal instances as keys in Maps is  
> impossible. Well, really hard.
> 
> The JPA spec requires support for float and double types but strongly  
> discourages their use. BigDecimal isn't even required due to these  
> problems.
> 
> Craig
> 
> On Jul 12, 2007, at 9:56 AM, Janap wrote:
> 
>>
>> Whoa....Enhancement works finally. I gave up the javaagent,fiddled  
>> around
>> with the Enhancer Task which all said the same thing .....
>>
>>  [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1 classes with
>> metadata in 0 milliseconds.
>>  [openjpac] 141  INFO   [main] openjpa.MetaData - The class  
>> "test.Scale"
>> listed in the openjpa.MetaDataFactory configuration property could  
>> not be
>> loaded; ignoring.
>>
>> i compiled it with the PCEnhancer java class. In Eclipse it is just  
>> a click
>> away.
>>
>> One more observation - I now am using the JPA Eclipse Plugin to  
>> generate
>> Entity classes and then enhance them. During this process, the  
>> enhancer once
>> complained that I cannot use "BigDecimal" as primary key.
>> The enhancement worked after I converted it to "long". Any ideas?
>>
>>
>>
>>
>>
>> Janap wrote:
>>>
>>> I have tried both the combinations Marc. I believe it might be a  
>>> problem
>>> with my class. I have to post the source tomorrow since I dont  
>>> carry my
>>> work to home :-) The classes are entity classes which I have reverse
>>> engineered using the Hibernate Tools plugin for Eclipse. They are  
>>> EJB 3.0
>>> compatible and work fine with hibernate.
>>>
>>> I appreciate the help,
>>> best wishes and good night
>>> Jan
>>>
>>>
>>> Patrick Linskey-2 wrote:
>>>>
>>>> Can you post the source to the Scale class?
>>>>
>>>> -Patrick
>>>>
>>>> On 7/11/07, Janap <ja...@gmail.com> wrote:
>>>>>
>>>>> Thx for the info Craig...got that step working. Didnt have time for
>>>>> research
>>>>> for the past2 days,but now Im back with another problem.
>>>>>
>>>>> My web project structure is as follows..
>>>>>
>>>>> /build/classes/test/Scale.class
>>>>>
>>>>> /src/test/Scale.java
>>>>>
>>>>> /web/WEB-INF/classes/META-INF/persistence.xml
>>>>> /web/WEB-INF/classes/META-INF/orm.xml
>>>>>
>>>>> /web/WEB-INF/lib
>>>>>
>>>>> Following is my persistence.xml
>>>>>
>>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>>> version="1.0">
>>>>> <persistence-unit name="myPersistence"
>>>>> transaction-type="RESOURCE_LOCAL">
>>>>>         <provider>
>>>>>             org.apache.openjpa.persistence.PersistenceProviderImpl
>>>>>         </provider>
>>>>>         <mapping-file>orm.xml</mapping-file>
>>>>>         <class>test.Scale</class>
>>>>>         <properties>
>>>>>             <property name="openjpa.ConnectionURL" value="myurl"/>
>>>>>             <property name="openjpa.ConnectionDriverName"
>>>>> value="oracle.jdbc.driver.OracleDriver"/>
>>>>>             <property name="openjpa.ConnectionUserName"  
>>>>> value="myuser"/>
>>>>>             <property name="openjpa.ConnectionPassword"  
>>>>> value="mypwd"/>
>>>>>             <property name="openjpa.Log"
>>>>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>>>>>         </properties>
>>>>> </persistence-unit>
>>>>> </persistence>
>>>>>
>>>>>
>>>>>
>>>>> For runtime enhancement is start Tomcat within Eclipse with the
>>>>> following VM
>>>>> arguments :
>>>>>
>>>>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
>>>>> \lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>>>>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
>>>>> \classes\META-INF\persistence.xml,-scanDevPath=true,
>>>>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build 
>>>>> \classes,-tmpClassLoader=false
>>>>>
>>>>>
>>>>> My Tomcat starts properly with the following log :
>>>>>
>>>>> 15  TRACE  [main] openjpa.Runtime - Setting the following  
>>>>> properties
>>>>> from
>>>>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/ 
>>>>> classes/META-INF/persistence.xml"
>>>>> into configuration: {openjpa.ConnectionUserName=myuser,
>>>>> openjpa.ConnectionPassword=mypwd,
>>>>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>>>>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>>>>> javax.persistence.provider=org.apache.openjpa.persistence.Persisten 
>>>>> ceProviderImpl,
>>>>> openjpa.ConnectionURL=myurl,
>>>>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>>>>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with  
>>>>> metadata in 0
>>>>> milliseconds.
>>>>>
>>>>>
>>>>> Then as I try to run this servlet code :
>>>>>
>>>>>         EntityManagerFactory emf =
>>>>> Persistence.createEntityManagerFactory("myPersistence");
>>>>>
>>>>>         EntityManager em = emf.createEntityManager();
>>>>>         em.getTransaction().begin();
>>>>>
>>>>>         Scale tab = new Scale(5);
>>>>>         em.persist(tab);
>>>>>         em.getTransaction().commit();
>>>>>         em.close();
>>>>>         emf.close();
>>>>>
>>>>> I run into an exception which I believe because my class is not  
>>>>> somehow
>>>>> enhanced :
>>>>>
>>>>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using  
>>>>> metadata
>>>>> factory
>>>>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0b 
>>>>> dc8".
>>>>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using  
>>>>> dictionary
>>>>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>>>>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1  
>>>>> classes
>>>>> with
>>>>> metadata in 16 milliseconds.
>>>>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/ 
>>>>> Scale"
>>>>> requires runtime enhancement: true
>>>>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An  
>>>>> exception was
>>>>> thrown while attempting to perform class file transformation on
>>>>> "test/Scale":
>>>>> java.lang.IllegalArgumentException:  
>>>>> java.lang.ClassNotFoundException:
>>>>> test.Scale
>>>>>         at serp.util.Strings.toClass(Strings.java:211)
>>>>>         at serp.util.Strings.toClass(Strings.java:140)
>>>>>         at serp.bytecode.BCClass.getType(BCClass.java:565)
>>>>>         at
>>>>> org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>>>>         at
>>>>> org.apache.openjpa.enhance.PCClassFileTransformer.transform 
>>>>> (PCClassFileTransformer.java:124)
>>>>>         at
>>>>> sun.instrument.TransformerManager.transform 
>>>>> (TransformerManager.java:122)
>>>>>         at
>>>>> sun.instrument.InstrumentationImpl.transform 
>>>>> (InstrumentationImpl.java:155)
>>>>>         at java.lang.ClassLoader.defineClass1(Native Method)
>>>>>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>>>>
>>>>>
>>>>> I tried out different combinations but was not  
>>>>> successful...probably
>>>>> someone
>>>>> could find the flaw..
>>>>>
>>>>> best wishes
>>>>> Jan
>>>>>
>>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> This is from the Java SE 6 documentation. It explains "all":
>>>>> Command-Line Interface
>>>>>
>>>>> On implementations with a command-line interface, an agent is  
>>>>> started
>>>>> by adding this option to the command-line:
>>>>>
>>>>> -javaagent:jarpath[=options]
>>>>> jarpath is the path to the agent JAR file. options is the agent
>>>>> options. This switch may be used multiple times on the same  
>>>>> command-
>>>>> line, thus creating multiple agents. More than one agent may use  
>>>>> the
>>>>> same jarpath. An agent JAR file must conform to the JAR file
>>>>> specification.
>>>>> The manifest of the agent JAR file must contain the attribute  
>>>>> Premain-
>>>>> Class. The value of this attribute is the name of the agent class.
>>>>> The agent class must implement a public static premain method  
>>>>> similar
>>>>> in principle to the main application entry point. After the Java
>>>>> Virtual Machine (JVM) has initialized, each premain method will be
>>>>> called in the order the agents were specified, then the real
>>>>> application main method will be called. Each premain method must
>>>>> return in order for the startup sequence to proceed.
>>>>> The premain method has one of two possible signatures. The JVM  
>>>>> first
>>>>> attempts to invoke the following method on the agent class:
>>>>> public static void premain(String agentArgs, Instrumentation inst);
>>>>> If the agent class does not implement this method then the JVM will
>>>>> attempt to invoke:
>>>>>
>>>>> public static void premain(String agentArgs);
>>>>> The agent class may also have an agentmain method for use when the
>>>>> agent is started after VM startup. When the agent is started  
>>>>> using a
>>>>> command-line option, the agentmain method is not invoked.
>>>>>
>>>>> The agent class will be loaded by the system class loader (see
>>>>> ClassLoader.getSystemClassLoader). This is the class loader which
>>>>> typically loads the class containing the application main  
>>>>> method. The
>>>>> premain methods will be run under the same security and classloader
>>>>> rules as the application main method. There are no modeling
>>>>> restrictions on what the agent premain method may do. Anything
>>>>> application main can do, including creating threads, is legal from
>>>>> premain.
>>>>>
>>>>> Each agent is passed its agent options via the agentArgs parameter.
>>>>> The agent options are passed as a single string, any additional
>>>>> parsing should be performed by the agent itself.
>>>>>
>>>>> If the agent cannot be resolved (for example, because the agent  
>>>>> class
>>>>> cannot be loaded, or because the agent class does not have an
>>>>> appropriate premain method), the JVM will abort. If a premain  
>>>>> method
>>>>> throws an uncaught exception, the JVM will abort.
>>>>>
>>>>>
>>>>>
>>>>> Craig
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse- 
>>>>> tf4049770.html#a11537016
>>>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>> -- 
>>>> Patrick Linskey
>>>> 202 669 5907
>>>>
>>>>
>>>
>>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Runtime- 
>> Enhancement-in-Eclipse-tf4049770.html#a11564182
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
> 
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
> 
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11565895
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Runtime Enhancement in Eclipse

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Janap,

I'd recommend you stay far away from BigDecimal fields for primary  
keys, even if your provider supports them.

The BigDecimal class has a strange notion of equality that makes it  
unsuitable for primary keys. That is, given BigDecimal instances A  
and B, the following can be true:

(0 == A .compareTo B) true
(A .equals B) false

This means that using BigDecimal instances as keys in Maps is  
impossible. Well, really hard.

The JPA spec requires support for float and double types but strongly  
discourages their use. BigDecimal isn't even required due to these  
problems.

Craig

On Jul 12, 2007, at 9:56 AM, Janap wrote:

>
> Whoa....Enhancement works finally. I gave up the javaagent,fiddled  
> around
> with the Enhancer Task which all said the same thing .....
>
>  [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1 classes with
> metadata in 0 milliseconds.
>  [openjpac] 141  INFO   [main] openjpa.MetaData - The class  
> "test.Scale"
> listed in the openjpa.MetaDataFactory configuration property could  
> not be
> loaded; ignoring.
>
> i compiled it with the PCEnhancer java class. In Eclipse it is just  
> a click
> away.
>
> One more observation - I now am using the JPA Eclipse Plugin to  
> generate
> Entity classes and then enhance them. During this process, the  
> enhancer once
> complained that I cannot use "BigDecimal" as primary key.
> The enhancement worked after I converted it to "long". Any ideas?
>
>
>
>
>
> Janap wrote:
>>
>> I have tried both the combinations Marc. I believe it might be a  
>> problem
>> with my class. I have to post the source tomorrow since I dont  
>> carry my
>> work to home :-) The classes are entity classes which I have reverse
>> engineered using the Hibernate Tools plugin for Eclipse. They are  
>> EJB 3.0
>> compatible and work fine with hibernate.
>>
>> I appreciate the help,
>> best wishes and good night
>> Jan
>>
>>
>> Patrick Linskey-2 wrote:
>>>
>>> Can you post the source to the Scale class?
>>>
>>> -Patrick
>>>
>>> On 7/11/07, Janap <ja...@gmail.com> wrote:
>>>>
>>>> Thx for the info Craig...got that step working. Didnt have time for
>>>> research
>>>> for the past2 days,but now Im back with another problem.
>>>>
>>>> My web project structure is as follows..
>>>>
>>>> /build/classes/test/Scale.class
>>>>
>>>> /src/test/Scale.java
>>>>
>>>> /web/WEB-INF/classes/META-INF/persistence.xml
>>>> /web/WEB-INF/classes/META-INF/orm.xml
>>>>
>>>> /web/WEB-INF/lib
>>>>
>>>> Following is my persistence.xml
>>>>
>>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>> version="1.0">
>>>> <persistence-unit name="myPersistence"
>>>> transaction-type="RESOURCE_LOCAL">
>>>>         <provider>
>>>>             org.apache.openjpa.persistence.PersistenceProviderImpl
>>>>         </provider>
>>>>         <mapping-file>orm.xml</mapping-file>
>>>>         <class>test.Scale</class>
>>>>         <properties>
>>>>             <property name="openjpa.ConnectionURL" value="myurl"/>
>>>>             <property name="openjpa.ConnectionDriverName"
>>>> value="oracle.jdbc.driver.OracleDriver"/>
>>>>             <property name="openjpa.ConnectionUserName"  
>>>> value="myuser"/>
>>>>             <property name="openjpa.ConnectionPassword"  
>>>> value="mypwd"/>
>>>>             <property name="openjpa.Log"
>>>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>>>>         </properties>
>>>> </persistence-unit>
>>>> </persistence>
>>>>
>>>>
>>>>
>>>> For runtime enhancement is start Tomcat within Eclipse with the
>>>> following VM
>>>> arguments :
>>>>
>>>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
>>>> \lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>>>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF 
>>>> \classes\META-INF\persistence.xml,-scanDevPath=true,
>>>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build 
>>>> \classes,-tmpClassLoader=false
>>>>
>>>>
>>>> My Tomcat starts properly with the following log :
>>>>
>>>> 15  TRACE  [main] openjpa.Runtime - Setting the following  
>>>> properties
>>>> from
>>>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/ 
>>>> classes/META-INF/persistence.xml"
>>>> into configuration: {openjpa.ConnectionUserName=myuser,
>>>> openjpa.ConnectionPassword=mypwd,
>>>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>>>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>>>> javax.persistence.provider=org.apache.openjpa.persistence.Persisten 
>>>> ceProviderImpl,
>>>> openjpa.ConnectionURL=myurl,
>>>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>>>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with  
>>>> metadata in 0
>>>> milliseconds.
>>>>
>>>>
>>>> Then as I try to run this servlet code :
>>>>
>>>>         EntityManagerFactory emf =
>>>> Persistence.createEntityManagerFactory("myPersistence");
>>>>
>>>>         EntityManager em = emf.createEntityManager();
>>>>         em.getTransaction().begin();
>>>>
>>>>         Scale tab = new Scale(5);
>>>>         em.persist(tab);
>>>>         em.getTransaction().commit();
>>>>         em.close();
>>>>         emf.close();
>>>>
>>>> I run into an exception which I believe because my class is not  
>>>> somehow
>>>> enhanced :
>>>>
>>>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using  
>>>> metadata
>>>> factory
>>>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0b 
>>>> dc8".
>>>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using  
>>>> dictionary
>>>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>>>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1  
>>>> classes
>>>> with
>>>> metadata in 16 milliseconds.
>>>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/ 
>>>> Scale"
>>>> requires runtime enhancement: true
>>>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An  
>>>> exception was
>>>> thrown while attempting to perform class file transformation on
>>>> "test/Scale":
>>>> java.lang.IllegalArgumentException:  
>>>> java.lang.ClassNotFoundException:
>>>> test.Scale
>>>>         at serp.util.Strings.toClass(Strings.java:211)
>>>>         at serp.util.Strings.toClass(Strings.java:140)
>>>>         at serp.bytecode.BCClass.getType(BCClass.java:565)
>>>>         at
>>>> org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>>>         at
>>>> org.apache.openjpa.enhance.PCClassFileTransformer.transform 
>>>> (PCClassFileTransformer.java:124)
>>>>         at
>>>> sun.instrument.TransformerManager.transform 
>>>> (TransformerManager.java:122)
>>>>         at
>>>> sun.instrument.InstrumentationImpl.transform 
>>>> (InstrumentationImpl.java:155)
>>>>         at java.lang.ClassLoader.defineClass1(Native Method)
>>>>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>>>
>>>>
>>>> I tried out different combinations but was not  
>>>> successful...probably
>>>> someone
>>>> could find the flaw..
>>>>
>>>> best wishes
>>>> Jan
>>>>
>>>>
>>>>
>>>> Hi,
>>>>
>>>> This is from the Java SE 6 documentation. It explains "all":
>>>> Command-Line Interface
>>>>
>>>> On implementations with a command-line interface, an agent is  
>>>> started
>>>> by adding this option to the command-line:
>>>>
>>>> -javaagent:jarpath[=options]
>>>> jarpath is the path to the agent JAR file. options is the agent
>>>> options. This switch may be used multiple times on the same  
>>>> command-
>>>> line, thus creating multiple agents. More than one agent may use  
>>>> the
>>>> same jarpath. An agent JAR file must conform to the JAR file
>>>> specification.
>>>> The manifest of the agent JAR file must contain the attribute  
>>>> Premain-
>>>> Class. The value of this attribute is the name of the agent class.
>>>> The agent class must implement a public static premain method  
>>>> similar
>>>> in principle to the main application entry point. After the Java
>>>> Virtual Machine (JVM) has initialized, each premain method will be
>>>> called in the order the agents were specified, then the real
>>>> application main method will be called. Each premain method must
>>>> return in order for the startup sequence to proceed.
>>>> The premain method has one of two possible signatures. The JVM  
>>>> first
>>>> attempts to invoke the following method on the agent class:
>>>> public static void premain(String agentArgs, Instrumentation inst);
>>>> If the agent class does not implement this method then the JVM will
>>>> attempt to invoke:
>>>>
>>>> public static void premain(String agentArgs);
>>>> The agent class may also have an agentmain method for use when the
>>>> agent is started after VM startup. When the agent is started  
>>>> using a
>>>> command-line option, the agentmain method is not invoked.
>>>>
>>>> The agent class will be loaded by the system class loader (see
>>>> ClassLoader.getSystemClassLoader). This is the class loader which
>>>> typically loads the class containing the application main  
>>>> method. The
>>>> premain methods will be run under the same security and classloader
>>>> rules as the application main method. There are no modeling
>>>> restrictions on what the agent premain method may do. Anything
>>>> application main can do, including creating threads, is legal from
>>>> premain.
>>>>
>>>> Each agent is passed its agent options via the agentArgs parameter.
>>>> The agent options are passed as a single string, any additional
>>>> parsing should be performed by the agent itself.
>>>>
>>>> If the agent cannot be resolved (for example, because the agent  
>>>> class
>>>> cannot be loaded, or because the agent class does not have an
>>>> appropriate premain method), the JVM will abort. If a premain  
>>>> method
>>>> throws an uncaught exception, the JVM will abort.
>>>>
>>>>
>>>>
>>>> Craig
>>>>
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse- 
>>>> tf4049770.html#a11537016
>>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>> -- 
>>> Patrick Linskey
>>> 202 669 5907
>>>
>>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Runtime- 
> Enhancement-in-Eclipse-tf4049770.html#a11564182
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.

Well..logically it should work for all classes defined in the
persistence.xml. I saw some posts where they did not specify the path to
persistence.xml (option :  -properties META-INF/persistence.xml) and
javaagent automatically looked for all persistent classes. But my Tomcat
doesnt startup if I dont specify a path to persistence.xml.

Anyhow I couldnt get it running with javaagent...I am just using eclipse to
enhance my classes.

Jan



Marina Vatkina wrote:
> 
> Janap,
> 
> I was wondering if running javaagent on Tomcat startup will only result in 
> enhancing Tomcat classes or is javaagent supposed to be smarter than that?
> 
> thanks,
> -marina
> 
> Janap wrote:
>> Whoa....Enhancement works finally. I gave up the javaagent,fiddled around
>> with the Enhancer Task which all said the same thing .....
>> 
>>  [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1 classes with
>> metadata in 0 milliseconds.
>>  [openjpac] 141  INFO   [main] openjpa.MetaData - The class "test.Scale"
>> listed in the openjpa.MetaDataFactory configuration property could not be
>> loaded; ignoring.
>> 
>> i compiled it with the PCEnhancer java class. In Eclipse it is just a
>> click
>> away.
>> 
>> One more observation - I now am using the JPA Eclipse Plugin to generate
>> Entity classes and then enhance them. During this process, the enhancer
>> once
>> complained that I cannot use "BigDecimal" as primary key.
>> The enhancement worked after I converted it to "long". Any ideas? 
>> 
>> 
>> 
>> 
>> 
>> Janap wrote:
>> 
>>>I have tried both the combinations Marc. I believe it might be a problem
>>>with my class. I have to post the source tomorrow since I dont carry my
>>>work to home :-) The classes are entity classes which I have reverse
>>>engineered using the Hibernate Tools plugin for Eclipse. They are EJB 3.0
>>>compatible and work fine with hibernate.
>>>
>>>I appreciate the help,
>>>best wishes and good night
>>>Jan
>>>
>>>
>>>Patrick Linskey-2 wrote:
>>>
>>>>Can you post the source to the Scale class?
>>>>
>>>>-Patrick
>>>>
>>>>On 7/11/07, Janap <ja...@gmail.com> wrote:
>>>>
>>>>>Thx for the info Craig...got that step working. Didnt have time for
>>>>>research
>>>>>for the past2 days,but now Im back with another problem.
>>>>>
>>>>>My web project structure is as follows..
>>>>>
>>>>>/build/classes/test/Scale.class
>>>>>
>>>>>/src/test/Scale.java
>>>>>
>>>>>/web/WEB-INF/classes/META-INF/persistence.xml
>>>>>/web/WEB-INF/classes/META-INF/orm.xml
>>>>>
>>>>>/web/WEB-INF/lib
>>>>>
>>>>>Following is my persistence.xml
>>>>>
>>>>><persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>>>version="1.0">
>>>>><persistence-unit name="myPersistence" 
>>>>>transaction-type="RESOURCE_LOCAL">
>>>>>        <provider>
>>>>>            org.apache.openjpa.persistence.PersistenceProviderImpl
>>>>>        </provider>
>>>>>        <mapping-file>orm.xml</mapping-file>
>>>>>        <class>test.Scale</class>
>>>>>        <properties>
>>>>>            <property name="openjpa.ConnectionURL" value="myurl"/>
>>>>>            <property name="openjpa.ConnectionDriverName"
>>>>>value="oracle.jdbc.driver.OracleDriver"/>
>>>>>            <property name="openjpa.ConnectionUserName"
>>>>> value="myuser"/>
>>>>>            <property name="openjpa.ConnectionPassword" value="mypwd"/>
>>>>>            <property name="openjpa.Log"
>>>>>value="DefaultLevel=TRACE,Tool=TRACE"/>
>>>>>        </properties>
>>>>></persistence-unit>
>>>>></persistence>
>>>>>
>>>>>
>>>>>
>>>>>For runtime enhancement is start Tomcat within Eclipse with the
>>>>>following VM
>>>>>arguments :
>>>>>
>>>>>-javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>>>>>,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\classes\META-INF\persistence.xml,-scanDevPath=true,
>>>>>directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,-tmpClassLoader=false
>>>>>
>>>>>
>>>>>My Tomcat starts properly with the following log :
>>>>>
>>>>>15  TRACE  [main] openjpa.Runtime - Setting the following properties
>>>>>from
>>>>>"file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/classes/META-INF/persistence.xml"
>>>>>into configuration: {openjpa.ConnectionUserName=myuser,
>>>>>openjpa.ConnectionPassword=mypwd,
>>>>>openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>>>>>openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>>>>>javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
>>>>>openjpa.ConnectionURL=myurl,
>>>>>openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>>>>>186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata in
0
>>>>>milliseconds.
>>>>>
>>>>>
>>>>>Then as I try to run this servlet code :
>>>>>
>>>>>        EntityManagerFactory emf =
>>>>>Persistence.createEntityManagerFactory("myPersistence");
>>>>>
>>>>>        EntityManager em = emf.createEntityManager();
>>>>>        em.getTransaction().begin();
>>>>>
>>>>>        Scale tab = new Scale(5);
>>>>>        em.persist(tab);
>>>>>        em.getTransaction().commit();
>>>>>        em.close();
>>>>>        emf.close();
>>>>>
>>>>>I run into an exception which I believe because my class is not somehow
>>>>>enhanced :
>>>>>
>>>>>62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using metadata
>>>>>factory
>>>>>"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8".
>>>>>93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using dictionary
>>>>>class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>>>>>202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1 classes
>>>>>with
>>>>>metadata in 16 milliseconds.
>>>>>95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
>>>>>requires runtime enhancement: true
>>>>>95561  WARN   [http-8090-Processor24] openjpa.Enhance - An exception
was
>>>>>thrown while attempting to perform class file transformation on
>>>>>"test/Scale":
>>>>>java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
>>>>>test.Scale
>>>>>        at serp.util.Strings.toClass(Strings.java:211)
>>>>>        at serp.util.Strings.toClass(Strings.java:140)
>>>>>        at serp.bytecode.BCClass.getType(BCClass.java:565)
>>>>>        at
>>>>>org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>>>>        at
>>>>>org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:124)
>>>>>        at
>>>>>sun.instrument.TransformerManager.transform(TransformerManager.java:122)
>>>>>        at
>>>>>sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
>>>>>        at java.lang.ClassLoader.defineClass1(Native Method)
>>>>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>>>>
>>>>>
>>>>>I tried out different combinations but was not successful...probably
>>>>>someone
>>>>>could find the flaw..
>>>>>
>>>>>best wishes
>>>>>Jan
>>>>>
>>>>>
>>>>>
>>>>>Hi,
>>>>>
>>>>>This is from the Java SE 6 documentation. It explains "all":
>>>>>Command-Line Interface
>>>>>
>>>>>On implementations with a command-line interface, an agent is started
>>>>>by adding this option to the command-line:
>>>>>
>>>>>-javaagent:jarpath[=options]
>>>>>jarpath is the path to the agent JAR file. options is the agent
>>>>>options. This switch may be used multiple times on the same command-
>>>>>line, thus creating multiple agents. More than one agent may use the
>>>>>same jarpath. An agent JAR file must conform to the JAR file
>>>>>specification.
>>>>>The manifest of the agent JAR file must contain the attribute Premain-
>>>>>Class. The value of this attribute is the name of the agent class.
>>>>>The agent class must implement a public static premain method similar
>>>>>in principle to the main application entry point. After the Java
>>>>>Virtual Machine (JVM) has initialized, each premain method will be
>>>>>called in the order the agents were specified, then the real
>>>>>application main method will be called. Each premain method must
>>>>>return in order for the startup sequence to proceed.
>>>>>The premain method has one of two possible signatures. The JVM first
>>>>>attempts to invoke the following method on the agent class:
>>>>>public static void premain(String agentArgs, Instrumentation inst);
>>>>>If the agent class does not implement this method then the JVM will
>>>>>attempt to invoke:
>>>>>
>>>>>public static void premain(String agentArgs);
>>>>>The agent class may also have an agentmain method for use when the
>>>>>agent is started after VM startup. When the agent is started using a
>>>>>command-line option, the agentmain method is not invoked.
>>>>>
>>>>>The agent class will be loaded by the system class loader (see
>>>>>ClassLoader.getSystemClassLoader). This is the class loader which
>>>>>typically loads the class containing the application main method. The
>>>>>premain methods will be run under the same security and classloader
>>>>>rules as the application main method. There are no modeling
>>>>>restrictions on what the agent premain method may do. Anything
>>>>>application main can do, including creating threads, is legal from
>>>>>premain.
>>>>>
>>>>>Each agent is passed its agent options via the agentArgs parameter.
>>>>>The agent options are passed as a single string, any additional
>>>>>parsing should be performed by the agent itself.
>>>>>
>>>>>If the agent cannot be resolved (for example, because the agent class
>>>>>cannot be loaded, or because the agent class does not have an
>>>>>appropriate premain method), the JVM will abort. If a premain method
>>>>>throws an uncaught exception, the JVM will abort.
>>>>>
>>>>>
>>>>>
>>>>>Craig
>>>>>
>>>>>
>>>>>
>>>>>--
>>>>>View this message in context:
>>>>>http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11537016
>>>>>Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>>-- 
>>>>Patrick Linskey
>>>>202 669 5907
>>>>
>>>>
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11575929
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Runtime Enhancement in Eclipse

Posted by Marina Vatkina <Ma...@Sun.COM>.
Janap,

I was wondering if running javaagent on Tomcat startup will only result in 
enhancing Tomcat classes or is javaagent supposed to be smarter than that?

thanks,
-marina

Janap wrote:
> Whoa....Enhancement works finally. I gave up the javaagent,fiddled around
> with the Enhancer Task which all said the same thing .....
> 
>  [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1 classes with
> metadata in 0 milliseconds.
>  [openjpac] 141  INFO   [main] openjpa.MetaData - The class "test.Scale"
> listed in the openjpa.MetaDataFactory configuration property could not be
> loaded; ignoring.
> 
> i compiled it with the PCEnhancer java class. In Eclipse it is just a click
> away.
> 
> One more observation - I now am using the JPA Eclipse Plugin to generate
> Entity classes and then enhance them. During this process, the enhancer once
> complained that I cannot use "BigDecimal" as primary key.
> The enhancement worked after I converted it to "long". Any ideas? 
> 
> 
> 
> 
> 
> Janap wrote:
> 
>>I have tried both the combinations Marc. I believe it might be a problem
>>with my class. I have to post the source tomorrow since I dont carry my
>>work to home :-) The classes are entity classes which I have reverse
>>engineered using the Hibernate Tools plugin for Eclipse. They are EJB 3.0
>>compatible and work fine with hibernate.
>>
>>I appreciate the help,
>>best wishes and good night
>>Jan
>>
>>
>>Patrick Linskey-2 wrote:
>>
>>>Can you post the source to the Scale class?
>>>
>>>-Patrick
>>>
>>>On 7/11/07, Janap <ja...@gmail.com> wrote:
>>>
>>>>Thx for the info Craig...got that step working. Didnt have time for
>>>>research
>>>>for the past2 days,but now Im back with another problem.
>>>>
>>>>My web project structure is as follows..
>>>>
>>>>/build/classes/test/Scale.class
>>>>
>>>>/src/test/Scale.java
>>>>
>>>>/web/WEB-INF/classes/META-INF/persistence.xml
>>>>/web/WEB-INF/classes/META-INF/orm.xml
>>>>
>>>>/web/WEB-INF/lib
>>>>
>>>>Following is my persistence.xml
>>>>
>>>><persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>>>version="1.0">
>>>><persistence-unit name="myPersistence" 
>>>>transaction-type="RESOURCE_LOCAL">
>>>>        <provider>
>>>>            org.apache.openjpa.persistence.PersistenceProviderImpl
>>>>        </provider>
>>>>        <mapping-file>orm.xml</mapping-file>
>>>>        <class>test.Scale</class>
>>>>        <properties>
>>>>            <property name="openjpa.ConnectionURL" value="myurl"/>
>>>>            <property name="openjpa.ConnectionDriverName"
>>>>value="oracle.jdbc.driver.OracleDriver"/>
>>>>            <property name="openjpa.ConnectionUserName" value="myuser"/>
>>>>            <property name="openjpa.ConnectionPassword" value="mypwd"/>
>>>>            <property name="openjpa.Log"
>>>>value="DefaultLevel=TRACE,Tool=TRACE"/>
>>>>        </properties>
>>>></persistence-unit>
>>>></persistence>
>>>>
>>>>
>>>>
>>>>For runtime enhancement is start Tomcat within Eclipse with the
>>>>following VM
>>>>arguments :
>>>>
>>>>-javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>>>>,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\classes\META-INF\persistence.xml,-scanDevPath=true,
>>>>directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,-tmpClassLoader=false
>>>>
>>>>
>>>>My Tomcat starts properly with the following log :
>>>>
>>>>15  TRACE  [main] openjpa.Runtime - Setting the following properties
>>>>from
>>>>"file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/classes/META-INF/persistence.xml"
>>>>into configuration: {openjpa.ConnectionUserName=myuser,
>>>>openjpa.ConnectionPassword=mypwd,
>>>>openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>>>>openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>>>>javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
>>>>openjpa.ConnectionURL=myurl,
>>>>openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>>>>186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata in 0
>>>>milliseconds.
>>>>
>>>>
>>>>Then as I try to run this servlet code :
>>>>
>>>>        EntityManagerFactory emf =
>>>>Persistence.createEntityManagerFactory("myPersistence");
>>>>
>>>>        EntityManager em = emf.createEntityManager();
>>>>        em.getTransaction().begin();
>>>>
>>>>        Scale tab = new Scale(5);
>>>>        em.persist(tab);
>>>>        em.getTransaction().commit();
>>>>        em.close();
>>>>        emf.close();
>>>>
>>>>I run into an exception which I believe because my class is not somehow
>>>>enhanced :
>>>>
>>>>62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using metadata
>>>>factory
>>>>"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8".
>>>>93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using dictionary
>>>>class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>>>>202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1 classes
>>>>with
>>>>metadata in 16 milliseconds.
>>>>95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
>>>>requires runtime enhancement: true
>>>>95561  WARN   [http-8090-Processor24] openjpa.Enhance - An exception was
>>>>thrown while attempting to perform class file transformation on
>>>>"test/Scale":
>>>>java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
>>>>test.Scale
>>>>        at serp.util.Strings.toClass(Strings.java:211)
>>>>        at serp.util.Strings.toClass(Strings.java:140)
>>>>        at serp.bytecode.BCClass.getType(BCClass.java:565)
>>>>        at
>>>>org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>>>        at
>>>>org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:124)
>>>>        at
>>>>sun.instrument.TransformerManager.transform(TransformerManager.java:122)
>>>>        at
>>>>sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
>>>>        at java.lang.ClassLoader.defineClass1(Native Method)
>>>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>>>
>>>>
>>>>I tried out different combinations but was not successful...probably
>>>>someone
>>>>could find the flaw..
>>>>
>>>>best wishes
>>>>Jan
>>>>
>>>>
>>>>
>>>>Hi,
>>>>
>>>>This is from the Java SE 6 documentation. It explains "all":
>>>>Command-Line Interface
>>>>
>>>>On implementations with a command-line interface, an agent is started
>>>>by adding this option to the command-line:
>>>>
>>>>-javaagent:jarpath[=options]
>>>>jarpath is the path to the agent JAR file. options is the agent
>>>>options. This switch may be used multiple times on the same command-
>>>>line, thus creating multiple agents. More than one agent may use the
>>>>same jarpath. An agent JAR file must conform to the JAR file
>>>>specification.
>>>>The manifest of the agent JAR file must contain the attribute Premain-
>>>>Class. The value of this attribute is the name of the agent class.
>>>>The agent class must implement a public static premain method similar
>>>>in principle to the main application entry point. After the Java
>>>>Virtual Machine (JVM) has initialized, each premain method will be
>>>>called in the order the agents were specified, then the real
>>>>application main method will be called. Each premain method must
>>>>return in order for the startup sequence to proceed.
>>>>The premain method has one of two possible signatures. The JVM first
>>>>attempts to invoke the following method on the agent class:
>>>>public static void premain(String agentArgs, Instrumentation inst);
>>>>If the agent class does not implement this method then the JVM will
>>>>attempt to invoke:
>>>>
>>>>public static void premain(String agentArgs);
>>>>The agent class may also have an agentmain method for use when the
>>>>agent is started after VM startup. When the agent is started using a
>>>>command-line option, the agentmain method is not invoked.
>>>>
>>>>The agent class will be loaded by the system class loader (see
>>>>ClassLoader.getSystemClassLoader). This is the class loader which
>>>>typically loads the class containing the application main method. The
>>>>premain methods will be run under the same security and classloader
>>>>rules as the application main method. There are no modeling
>>>>restrictions on what the agent premain method may do. Anything
>>>>application main can do, including creating threads, is legal from
>>>>premain.
>>>>
>>>>Each agent is passed its agent options via the agentArgs parameter.
>>>>The agent options are passed as a single string, any additional
>>>>parsing should be performed by the agent itself.
>>>>
>>>>If the agent cannot be resolved (for example, because the agent class
>>>>cannot be loaded, or because the agent class does not have an
>>>>appropriate premain method), the JVM will abort. If a premain method
>>>>throws an uncaught exception, the JVM will abort.
>>>>
>>>>
>>>>
>>>>Craig
>>>>
>>>>
>>>>
>>>>--
>>>>View this message in context:
>>>>http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11537016
>>>>Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>-- 
>>>Patrick Linskey
>>>202 669 5907
>>>
>>>
>>
>>
> 


Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.
Whoa....Enhancement works finally. I gave up the javaagent,fiddled around
with the Enhancer Task which all said the same thing .....

 [openjpac] 141  INFO   [main] openjpa.MetaData - Found 1 classes with
metadata in 0 milliseconds.
 [openjpac] 141  INFO   [main] openjpa.MetaData - The class "test.Scale"
listed in the openjpa.MetaDataFactory configuration property could not be
loaded; ignoring.

i compiled it with the PCEnhancer java class. In Eclipse it is just a click
away.

One more observation - I now am using the JPA Eclipse Plugin to generate
Entity classes and then enhance them. During this process, the enhancer once
complained that I cannot use "BigDecimal" as primary key.
The enhancement worked after I converted it to "long". Any ideas? 





Janap wrote:
> 
> I have tried both the combinations Marc. I believe it might be a problem
> with my class. I have to post the source tomorrow since I dont carry my
> work to home :-) The classes are entity classes which I have reverse
> engineered using the Hibernate Tools plugin for Eclipse. They are EJB 3.0
> compatible and work fine with hibernate.
> 
> I appreciate the help,
> best wishes and good night
> Jan
> 
> 
> Patrick Linskey-2 wrote:
>> 
>> Can you post the source to the Scale class?
>> 
>> -Patrick
>> 
>> On 7/11/07, Janap <ja...@gmail.com> wrote:
>>>
>>> Thx for the info Craig...got that step working. Didnt have time for
>>> research
>>> for the past2 days,but now Im back with another problem.
>>>
>>> My web project structure is as follows..
>>>
>>> /build/classes/test/Scale.class
>>>
>>> /src/test/Scale.java
>>>
>>> /web/WEB-INF/classes/META-INF/persistence.xml
>>> /web/WEB-INF/classes/META-INF/orm.xml
>>>
>>> /web/WEB-INF/lib
>>>
>>> Following is my persistence.xml
>>>
>>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>>> version="1.0">
>>> <persistence-unit name="myPersistence" 
>>> transaction-type="RESOURCE_LOCAL">
>>>         <provider>
>>>             org.apache.openjpa.persistence.PersistenceProviderImpl
>>>         </provider>
>>>         <mapping-file>orm.xml</mapping-file>
>>>         <class>test.Scale</class>
>>>         <properties>
>>>             <property name="openjpa.ConnectionURL" value="myurl"/>
>>>             <property name="openjpa.ConnectionDriverName"
>>> value="oracle.jdbc.driver.OracleDriver"/>
>>>             <property name="openjpa.ConnectionUserName" value="myuser"/>
>>>             <property name="openjpa.ConnectionPassword" value="mypwd"/>
>>>             <property name="openjpa.Log"
>>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>>>         </properties>
>>> </persistence-unit>
>>> </persistence>
>>>
>>>
>>>
>>> For runtime enhancement is start Tomcat within Eclipse with the
>>> following VM
>>> arguments :
>>>
>>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\classes\META-INF\persistence.xml,-scanDevPath=true,
>>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,-tmpClassLoader=false
>>>
>>>
>>> My Tomcat starts properly with the following log :
>>>
>>> 15  TRACE  [main] openjpa.Runtime - Setting the following properties
>>> from
>>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/classes/META-INF/persistence.xml"
>>> into configuration: {openjpa.ConnectionUserName=myuser,
>>> openjpa.ConnectionPassword=mypwd,
>>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>>> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
>>> openjpa.ConnectionURL=myurl,
>>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata in 0
>>> milliseconds.
>>>
>>>
>>> Then as I try to run this servlet code :
>>>
>>>         EntityManagerFactory emf =
>>> Persistence.createEntityManagerFactory("myPersistence");
>>>
>>>         EntityManager em = emf.createEntityManager();
>>>         em.getTransaction().begin();
>>>
>>>         Scale tab = new Scale(5);
>>>         em.persist(tab);
>>>         em.getTransaction().commit();
>>>         em.close();
>>>         emf.close();
>>>
>>> I run into an exception which I believe because my class is not somehow
>>> enhanced :
>>>
>>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using metadata
>>> factory
>>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8".
>>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using dictionary
>>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1 classes
>>> with
>>> metadata in 16 milliseconds.
>>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
>>> requires runtime enhancement: true
>>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An exception was
>>> thrown while attempting to perform class file transformation on
>>> "test/Scale":
>>> java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
>>> test.Scale
>>>         at serp.util.Strings.toClass(Strings.java:211)
>>>         at serp.util.Strings.toClass(Strings.java:140)
>>>         at serp.bytecode.BCClass.getType(BCClass.java:565)
>>>         at
>>> org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>>         at
>>> org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:124)
>>>         at
>>> sun.instrument.TransformerManager.transform(TransformerManager.java:122)
>>>         at
>>> sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
>>>         at java.lang.ClassLoader.defineClass1(Native Method)
>>>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>>
>>>
>>> I tried out different combinations but was not successful...probably
>>> someone
>>> could find the flaw..
>>>
>>> best wishes
>>> Jan
>>>
>>>
>>>
>>> Hi,
>>>
>>> This is from the Java SE 6 documentation. It explains "all":
>>> Command-Line Interface
>>>
>>> On implementations with a command-line interface, an agent is started
>>> by adding this option to the command-line:
>>>
>>> -javaagent:jarpath[=options]
>>> jarpath is the path to the agent JAR file. options is the agent
>>> options. This switch may be used multiple times on the same command-
>>> line, thus creating multiple agents. More than one agent may use the
>>> same jarpath. An agent JAR file must conform to the JAR file
>>> specification.
>>> The manifest of the agent JAR file must contain the attribute Premain-
>>> Class. The value of this attribute is the name of the agent class.
>>> The agent class must implement a public static premain method similar
>>> in principle to the main application entry point. After the Java
>>> Virtual Machine (JVM) has initialized, each premain method will be
>>> called in the order the agents were specified, then the real
>>> application main method will be called. Each premain method must
>>> return in order for the startup sequence to proceed.
>>> The premain method has one of two possible signatures. The JVM first
>>> attempts to invoke the following method on the agent class:
>>> public static void premain(String agentArgs, Instrumentation inst);
>>> If the agent class does not implement this method then the JVM will
>>> attempt to invoke:
>>>
>>> public static void premain(String agentArgs);
>>> The agent class may also have an agentmain method for use when the
>>> agent is started after VM startup. When the agent is started using a
>>> command-line option, the agentmain method is not invoked.
>>>
>>> The agent class will be loaded by the system class loader (see
>>> ClassLoader.getSystemClassLoader). This is the class loader which
>>> typically loads the class containing the application main method. The
>>> premain methods will be run under the same security and classloader
>>> rules as the application main method. There are no modeling
>>> restrictions on what the agent premain method may do. Anything
>>> application main can do, including creating threads, is legal from
>>> premain.
>>>
>>> Each agent is passed its agent options via the agentArgs parameter.
>>> The agent options are passed as a single string, any additional
>>> parsing should be performed by the agent itself.
>>>
>>> If the agent cannot be resolved (for example, because the agent class
>>> cannot be loaded, or because the agent class does not have an
>>> appropriate premain method), the JVM will abort. If a premain method
>>> throws an uncaught exception, the JVM will abort.
>>>
>>>
>>>
>>> Craig
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11537016
>>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> -- 
>> Patrick Linskey
>> 202 669 5907
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11564182
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.
I have tried both the combinations Marc. I believe it might be a problem with
my class. I have to post the source tomorrow since I dont carry my work to
home :-) The classes are entity classes which I have reverse engineered
using the Hibernate Tools plugin for Eclipse. They are EJB 3.0 compatible
and work fine with hibernate.

I appreciate the help,
best wishes and good night
Jan


Patrick Linskey-2 wrote:
> 
> Can you post the source to the Scale class?
> 
> -Patrick
> 
> On 7/11/07, Janap <ja...@gmail.com> wrote:
>>
>> Thx for the info Craig...got that step working. Didnt have time for
>> research
>> for the past2 days,but now Im back with another problem.
>>
>> My web project structure is as follows..
>>
>> /build/classes/test/Scale.class
>>
>> /src/test/Scale.java
>>
>> /web/WEB-INF/classes/META-INF/persistence.xml
>> /web/WEB-INF/classes/META-INF/orm.xml
>>
>> /web/WEB-INF/lib
>>
>> Following is my persistence.xml
>>
>> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>> version="1.0">
>> <persistence-unit name="myPersistence" 
>> transaction-type="RESOURCE_LOCAL">
>>         <provider>
>>             org.apache.openjpa.persistence.PersistenceProviderImpl
>>         </provider>
>>         <mapping-file>orm.xml</mapping-file>
>>         <class>test.Scale</class>
>>         <properties>
>>             <property name="openjpa.ConnectionURL" value="myurl"/>
>>             <property name="openjpa.ConnectionDriverName"
>> value="oracle.jdbc.driver.OracleDriver"/>
>>             <property name="openjpa.ConnectionUserName" value="myuser"/>
>>             <property name="openjpa.ConnectionPassword" value="mypwd"/>
>>             <property name="openjpa.Log"
>> value="DefaultLevel=TRACE,Tool=TRACE"/>
>>         </properties>
>> </persistence-unit>
>> </persistence>
>>
>>
>>
>> For runtime enhancement is start Tomcat within Eclipse with the following
>> VM
>> arguments :
>>
>> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
>> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\classes\META-INF\persistence.xml,-scanDevPath=true,
>> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,-tmpClassLoader=false
>>
>>
>> My Tomcat starts properly with the following log :
>>
>> 15  TRACE  [main] openjpa.Runtime - Setting the following properties from
>> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/classes/META-INF/persistence.xml"
>> into configuration: {openjpa.ConnectionUserName=myuser,
>> openjpa.ConnectionPassword=mypwd,
>> openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
>> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
>> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
>> openjpa.ConnectionURL=myurl,
>> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
>> 186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata in 0
>> milliseconds.
>>
>>
>> Then as I try to run this servlet code :
>>
>>         EntityManagerFactory emf =
>> Persistence.createEntityManagerFactory("myPersistence");
>>
>>         EntityManager em = emf.createEntityManager();
>>         em.getTransaction().begin();
>>
>>         Scale tab = new Scale(5);
>>         em.persist(tab);
>>         em.getTransaction().commit();
>>         em.close();
>>         emf.close();
>>
>> I run into an exception which I believe because my class is not somehow
>> enhanced :
>>
>> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using metadata
>> factory
>> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8".
>> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using dictionary
>> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
>> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1 classes
>> with
>> metadata in 16 milliseconds.
>> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
>> requires runtime enhancement: true
>> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An exception was
>> thrown while attempting to perform class file transformation on
>> "test/Scale":
>> java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
>> test.Scale
>>         at serp.util.Strings.toClass(Strings.java:211)
>>         at serp.util.Strings.toClass(Strings.java:140)
>>         at serp.bytecode.BCClass.getType(BCClass.java:565)
>>         at
>> org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>>         at
>> org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:124)
>>         at
>> sun.instrument.TransformerManager.transform(TransformerManager.java:122)
>>         at
>> sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
>>         at java.lang.ClassLoader.defineClass1(Native Method)
>>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>>
>>
>> I tried out different combinations but was not successful...probably
>> someone
>> could find the flaw..
>>
>> best wishes
>> Jan
>>
>>
>>
>> Hi,
>>
>> This is from the Java SE 6 documentation. It explains "all":
>> Command-Line Interface
>>
>> On implementations with a command-line interface, an agent is started
>> by adding this option to the command-line:
>>
>> -javaagent:jarpath[=options]
>> jarpath is the path to the agent JAR file. options is the agent
>> options. This switch may be used multiple times on the same command-
>> line, thus creating multiple agents. More than one agent may use the
>> same jarpath. An agent JAR file must conform to the JAR file
>> specification.
>> The manifest of the agent JAR file must contain the attribute Premain-
>> Class. The value of this attribute is the name of the agent class.
>> The agent class must implement a public static premain method similar
>> in principle to the main application entry point. After the Java
>> Virtual Machine (JVM) has initialized, each premain method will be
>> called in the order the agents were specified, then the real
>> application main method will be called. Each premain method must
>> return in order for the startup sequence to proceed.
>> The premain method has one of two possible signatures. The JVM first
>> attempts to invoke the following method on the agent class:
>> public static void premain(String agentArgs, Instrumentation inst);
>> If the agent class does not implement this method then the JVM will
>> attempt to invoke:
>>
>> public static void premain(String agentArgs);
>> The agent class may also have an agentmain method for use when the
>> agent is started after VM startup. When the agent is started using a
>> command-line option, the agentmain method is not invoked.
>>
>> The agent class will be loaded by the system class loader (see
>> ClassLoader.getSystemClassLoader). This is the class loader which
>> typically loads the class containing the application main method. The
>> premain methods will be run under the same security and classloader
>> rules as the application main method. There are no modeling
>> restrictions on what the agent premain method may do. Anything
>> application main can do, including creating threads, is legal from
>> premain.
>>
>> Each agent is passed its agent options via the agentArgs parameter.
>> The agent options are passed as a single string, any additional
>> parsing should be performed by the agent itself.
>>
>> If the agent cannot be resolved (for example, because the agent class
>> cannot be loaded, or because the agent class does not have an
>> appropriate premain method), the JVM will abort. If a premain method
>> throws an uncaught exception, the JVM will abort.
>>
>>
>>
>> Craig
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11537016
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Patrick Linskey
> 202 669 5907
> 
> 

-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11548186
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Runtime Enhancement in Eclipse

Posted by Patrick Linskey <pl...@gmail.com>.
Can you post the source to the Scale class?

-Patrick

On 7/11/07, Janap <ja...@gmail.com> wrote:
>
> Thx for the info Craig...got that step working. Didnt have time for research
> for the past2 days,but now Im back with another problem.
>
> My web project structure is as follows..
>
> /build/classes/test/Scale.class
>
> /src/test/Scale.java
>
> /web/WEB-INF/classes/META-INF/persistence.xml
> /web/WEB-INF/classes/META-INF/orm.xml
>
> /web/WEB-INF/lib
>
> Following is my persistence.xml
>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
> <persistence-unit name="myPersistence"  transaction-type="RESOURCE_LOCAL">
>         <provider>
>             org.apache.openjpa.persistence.PersistenceProviderImpl
>         </provider>
>         <mapping-file>orm.xml</mapping-file>
>         <class>test.Scale</class>
>         <properties>
>             <property name="openjpa.ConnectionURL" value="myurl"/>
>             <property name="openjpa.ConnectionDriverName"
> value="oracle.jdbc.driver.OracleDriver"/>
>             <property name="openjpa.ConnectionUserName" value="myuser"/>
>             <property name="openjpa.ConnectionPassword" value="mypwd"/>
>             <property name="openjpa.Log"
> value="DefaultLevel=TRACE,Tool=TRACE"/>
>         </properties>
> </persistence-unit>
> </persistence>
>
>
>
> For runtime enhancement is start Tomcat within Eclipse with the following VM
> arguments :
>
> -javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
> ,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\classes\META-INF\persistence.xml,-scanDevPath=true,
> directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,-tmpClassLoader=false
>
>
> My Tomcat starts properly with the following log :
>
> 15  TRACE  [main] openjpa.Runtime - Setting the following properties from
> "file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/classes/META-INF/persistence.xml"
> into configuration: {openjpa.ConnectionUserName=myuser,
> openjpa.ConnectionPassword=mypwd, openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
> openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
> javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
> openjpa.ConnectionURL=myurl,
> openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
> 186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata in 0
> milliseconds.
>
>
> Then as I try to run this servlet code :
>
>         EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("myPersistence");
>
>         EntityManager em = emf.createEntityManager();
>         em.getTransaction().begin();
>
>         Scale tab = new Scale(5);
>         em.persist(tab);
>         em.getTransaction().commit();
>         em.close();
>         emf.close();
>
> I run into an exception which I believe because my class is not somehow
> enhanced :
>
> 62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using metadata factory
> "org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8".
> 93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using dictionary
> class "org.apache.openjpa.jdbc.sql.OracleDictionary".
> 202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1 classes with
> metadata in 16 milliseconds.
> 95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
> requires runtime enhancement: true
> 95561  WARN   [http-8090-Processor24] openjpa.Enhance - An exception was
> thrown while attempting to perform class file transformation on
> "test/Scale":
> java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
> test.Scale
>         at serp.util.Strings.toClass(Strings.java:211)
>         at serp.util.Strings.toClass(Strings.java:140)
>         at serp.bytecode.BCClass.getType(BCClass.java:565)
>         at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
>         at
> org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:124)
>         at sun.instrument.TransformerManager.transform(TransformerManager.java:122)
>         at
> sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
>
>
> I tried out different combinations but was not successful...probably someone
> could find the flaw..
>
> best wishes
> Jan
>
>
>
> Hi,
>
> This is from the Java SE 6 documentation. It explains "all":
> Command-Line Interface
>
> On implementations with a command-line interface, an agent is started
> by adding this option to the command-line:
>
> -javaagent:jarpath[=options]
> jarpath is the path to the agent JAR file. options is the agent
> options. This switch may be used multiple times on the same command-
> line, thus creating multiple agents. More than one agent may use the
> same jarpath. An agent JAR file must conform to the JAR file
> specification.
> The manifest of the agent JAR file must contain the attribute Premain-
> Class. The value of this attribute is the name of the agent class.
> The agent class must implement a public static premain method similar
> in principle to the main application entry point. After the Java
> Virtual Machine (JVM) has initialized, each premain method will be
> called in the order the agents were specified, then the real
> application main method will be called. Each premain method must
> return in order for the startup sequence to proceed.
> The premain method has one of two possible signatures. The JVM first
> attempts to invoke the following method on the agent class:
> public static void premain(String agentArgs, Instrumentation inst);
> If the agent class does not implement this method then the JVM will
> attempt to invoke:
>
> public static void premain(String agentArgs);
> The agent class may also have an agentmain method for use when the
> agent is started after VM startup. When the agent is started using a
> command-line option, the agentmain method is not invoked.
>
> The agent class will be loaded by the system class loader (see
> ClassLoader.getSystemClassLoader). This is the class loader which
> typically loads the class containing the application main method. The
> premain methods will be run under the same security and classloader
> rules as the application main method. There are no modeling
> restrictions on what the agent premain method may do. Anything
> application main can do, including creating threads, is legal from
> premain.
>
> Each agent is passed its agent options via the agentArgs parameter.
> The agent options are passed as a single string, any additional
> parsing should be performed by the agent itself.
>
> If the agent cannot be resolved (for example, because the agent class
> cannot be loaded, or because the agent class does not have an
> appropriate premain method), the JVM will abort. If a premain method
> throws an uncaught exception, the JVM will abort.
>
>
>
> Craig
>
>
>
> --
> View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11537016
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>


-- 
Patrick Linskey
202 669 5907

Re: Runtime Enhancement in Eclipse

Posted by Janap <ja...@gmail.com>.
Thx for the info Craig...got that step working. Didnt have time for research
for the past2 days,but now Im back with another problem.

My web project structure is as follows..

/build/classes/test/Scale.class

/src/test/Scale.java

/web/WEB-INF/classes/META-INF/persistence.xml
/web/WEB-INF/classes/META-INF/orm.xml

/web/WEB-INF/lib

Following is my persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="myPersistence"  transaction-type="RESOURCE_LOCAL">
        <provider>
            org.apache.openjpa.persistence.PersistenceProviderImpl
        </provider>
        <mapping-file>orm.xml</mapping-file>
        <class>test.Scale</class>
        <properties>
            <property name="openjpa.ConnectionURL" value="myurl"/>
            <property name="openjpa.ConnectionDriverName"
value="oracle.jdbc.driver.OracleDriver"/>
            <property name="openjpa.ConnectionUserName" value="myuser"/>
            <property name="openjpa.ConnectionPassword" value="mypwd"/>
            <property name="openjpa.Log"
value="DefaultLevel=TRACE,Tool=TRACE"/>
        </properties>
</persistence-unit>
</persistence>



For runtime enhancement is start Tomcat within Eclipse with the following VM
arguments :

-javaagent:C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\lib\openjpa-all-0.9.6-incubating.jar=addDefaultConstructor=false
,properties=C:\Programme\Eclipse\workspace\JPAWebTest\web\WEB-INF\classes\META-INF\persistence.xml,-scanDevPath=true,
directory=C:\Programme\Eclipse\workspace\JPAWebTest\build\classes,-tmpClassLoader=false


My Tomcat starts properly with the following log : 

15  TRACE  [main] openjpa.Runtime - Setting the following properties from
"file:/C:/Programme/Eclipse/workspace/JPAWebTest/web/WEB-INF/classes/META-INF/persistence.xml"
into configuration: {openjpa.ConnectionUserName=myuser,
openjpa.ConnectionPassword=mypwd, openjpa.Log=DefaultLevel=TRACE,Tool=TRACE,
openjpa.MetaDataFactory=Resources=orm.xml, Types=test.Scale,
javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
openjpa.ConnectionURL=myurl,
openjpa.ConnectionDriverName=oracle.jdbc.driver.OracleDriver}
186  INFO   [main] openjpa.MetaData - Found 1 classes with metadata in 0
milliseconds.


Then as I try to run this servlet code :

    	EntityManagerFactory emf =
Persistence.createEntityManagerFactory("myPersistence");

    	EntityManager em = emf.createEntityManager();
    	em.getTransaction().begin();

    	Scale tab = new Scale(5);
    	em.persist(tab);
    	em.getTransaction().commit();
    	em.close();
    	emf.close();

I run into an exception which I believe because my class is not somehow
enhanced :

62  TRACE  [http-8090-Processor24] openjpa.MetaData - Using metadata factory
"org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory@1b0bdc8".
93  INFO   [http-8090-Processor24] openjpa.jdbc.JDBC - Using dictionary
class "org.apache.openjpa.jdbc.sql.OracleDictionary".
202  INFO   [http-8090-Processor24] openjpa.MetaData - Found 1 classes with
metadata in 16 milliseconds.
95452  TRACE  [http-8090-Processor24] openjpa.Enhance - "test/Scale"
requires runtime enhancement: true
95561  WARN   [http-8090-Processor24] openjpa.Enhance - An exception was
thrown while attempting to perform class file transformation on
"test/Scale":
java.lang.IllegalArgumentException: java.lang.ClassNotFoundException:
test.Scale
	at serp.util.Strings.toClass(Strings.java:211)
	at serp.util.Strings.toClass(Strings.java:140)
	at serp.bytecode.BCClass.getType(BCClass.java:565)
	at org.apache.openjpa.enhance.PCEnhancer.<init>(PCEnhancer.java:187)
	at
org.apache.openjpa.enhance.PCClassFileTransformer.transform(PCClassFileTransformer.java:124)
	at sun.instrument.TransformerManager.transform(TransformerManager.java:122)
	at
sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:620)


I tried out different combinations but was not successful...probably someone
could find the flaw..

best wishes
Jan



Hi,

This is from the Java SE 6 documentation. It explains "all":
Command-Line Interface

On implementations with a command-line interface, an agent is started  
by adding this option to the command-line:

-javaagent:jarpath[=options]
jarpath is the path to the agent JAR file. options is the agent  
options. This switch may be used multiple times on the same command- 
line, thus creating multiple agents. More than one agent may use the  
same jarpath. An agent JAR file must conform to the JAR file  
specification.
The manifest of the agent JAR file must contain the attribute Premain- 
Class. The value of this attribute is the name of the agent class.  
The agent class must implement a public static premain method similar  
in principle to the main application entry point. After the Java  
Virtual Machine (JVM) has initialized, each premain method will be  
called in the order the agents were specified, then the real  
application main method will be called. Each premain method must  
return in order for the startup sequence to proceed.
The premain method has one of two possible signatures. The JVM first  
attempts to invoke the following method on the agent class:
public static void premain(String agentArgs, Instrumentation inst);
If the agent class does not implement this method then the JVM will  
attempt to invoke:

public static void premain(String agentArgs);
The agent class may also have an agentmain method for use when the  
agent is started after VM startup. When the agent is started using a  
command-line option, the agentmain method is not invoked.

The agent class will be loaded by the system class loader (see  
ClassLoader.getSystemClassLoader). This is the class loader which  
typically loads the class containing the application main method. The  
premain methods will be run under the same security and classloader  
rules as the application main method. There are no modeling  
restrictions on what the agent premain method may do. Anything  
application main can do, including creating threads, is legal from  
premain.

Each agent is passed its agent options via the agentArgs parameter.  
The agent options are passed as a single string, any additional  
parsing should be performed by the agent itself.

If the agent cannot be resolved (for example, because the agent class  
cannot be loaded, or because the agent class does not have an  
appropriate premain method), the JVM will abort. If a premain method  
throws an uncaught exception, the JVM will abort.



Craig



-- 
View this message in context: http://www.nabble.com/Runtime-Enhancement-in-Eclipse-tf4049770.html#a11537016
Sent from the OpenJPA Users mailing list archive at Nabble.com.