You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Gilberto C Andrade <gi...@secad.to.gov.br> on 2008/01/02 21:02:24 UTC

Re: jpa provider

Hi, hope everyone is ok!

(OBS.: I think this post is report e not a request!
	And sorry, it is a little long. )

We are doing tests with annotated POJO and using orm (I mean using xml).
This is done with the following persistence.xml file:

> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
>     <persistence-unit name="annotatedPU" transaction-type="RESOURCE_LOCAL">
>         <provider>org.apache.cayenne.jpa.Provider</provider>
>         <mapping-file>META-INF/orm.xml</mapping-file>
>         <class>com.gilbertoca.gfi.model.inventario.UnidadeMedida</class>
>         <class>com.gilbertoca.gfi.model.inventario.Produto</class>    
>         <class>com.gilbertoca.gfi.model.inventario.Categoria</class>
>         <class>com.gilbertoca.gfi.model.inventario.Item</class>
>         <properties>
>             <property name="org.apache.cayenne.datasource.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
>             <property name="org.apache.cayenne.datasource.jdbc.url" value="jdbc:derby:gfi_db;create=true"/>
>             <property name="org.apache.cayenne.datasource.jdbc.username" value="gfi"/>
>             <property name="org.apache.cayenne.datasource.jdbc.password" value="value"/>
>             <property name="org.apache.cayenne.schema.create" value="false"/>
>         </properties>
>     </persistence-unit>
>     <persistence-unit name="metadataPU" transaction-type="RESOURCE_LOCAL">
>         <provider>org.apache.cayenne.jpa.Provider</provider>
>         <mapping-file>META-INF/inventario.xml</mapping-file>
>         <class>com.gilbertoca.gfi.model.inventario2.Categoria</class>
>         <properties>
>             <property name="org.apache.cayenne.datasource.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
>             <property name="org.apache.cayenne.datasource.jdbc.url" value="jdbc:derby:gfi_db;create=true"/>
>             <property name="org.apache.cayenne.datasource.jdbc.username" value="gfi"/>
>             <property name="org.apache.cayenne.datasource.jdbc.password" value="value"/>
>             <property name="org.apache.cayenne.schema.create" value="false"/>
>         </properties>
>     </persistence-unit>    
>     </persistence-unit>
> </persistence>


The tests pass while using toplink and openjpa provider. And as you did
see on last post, the cayenne Enhancer doesn't work (I used cayenne
3.0M2 and cayenne 3.0-SNAPSHOT). But don't worry, I'm just trying to help!
This way, while putting openjpa to enhance our POJOS, I could see that
they using an maven ant pluging. So, I've tried it too, but I don't know
 if I'm using it correctly or if the shot was right:
>             <id>cayenne</id>
>             <build>
>                 <plugins>
>                     <plugin>
>                         <artifactId>maven-antrun-plugin</artifactId>
>                         <executions>
>                             <execution>
>                                 <phase>process-classes</phase>
>                                 <configuration>
>                                     <tasks>
>                                         <java classname="org.apache.cayenne.enhancer.Enhancer"
>                                               classpathref="maven.runtime.classpath"
>                                               dir="target/classes" fork="true" />
>                                     </tasks>
>                                 </configuration>
>                                 <goals>
>                                     <goal>run</goal>
>                                 </goals>
>                             </execution>
>                         </executions>
>                     </plugin>
>                 </plugins>
>                 
>                 <!--plugins>
>                     <plugin>
>                         <groupId>org.apache.maven.plugins</groupId>
>                         <artifactId>maven-surefire-plugin</artifactId>
>                         <configuration>
>                             <useSystemClassLoader>true</useSystemClassLoader> 
>                             <forkMode>once</forkMode>
>                             <argLine>
>                                 -javaagent:${settings.localRepository}/org/apache/cayenne/cayenne-agent/${jpa_agent.version}/cayenne-agent-${jpa_agent.version}.jar
>                             </argLine>
>                         </configuration>
>                     </plugin>                     
>                 </plugins-->

I'm using only the metadataPU persistence unit, which are using the
<mapping-file>META-INF/inventario.xml</mapping-file> file:

> <?xml version="1.0" encoding="UTF-8"?> 
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" 
>                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>                  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd http://incubator.apache.org/openjpa/orm http://incubator.apache.org/openjpa/xml/ns/persistence/openjpa_orm_1_0.xsd"
>                  version="1.0">
>     
>     <persistence-unit-metadata>
>         <persistence-unit-defaults>
>             <schema>gfi</schema>
>         </persistence-unit-defaults>
>     </persistence-unit-metadata>     
>     <entity class="com.gilbertoca.gfi.model.inventario2.Categoria">
>         <table name="CATEGORIA" schema="GFI"/>
>         <attributes>
>             <id name="cdCategoria">
>                 <column name="CD_CATEGORIA" column-definition="INTEGER"/>
>             </id>
>             <basic name="nomeCategoria">
>                 <column name="NOME_CATEGORIA" length="80"/>
>             </basic>
>             <basic name="descricaoCategoria">
>                 <column name="DESCRICAO_CATEGORIA" length="255"/>
>             </basic>
>             <basic name="dtCadastro">
>                 <column name="DT_CADASTRO"/>
>             </basic>
>         </attributes>
>     </entity>
>     
> </entity-mappings>

The results:

> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Running com.gilbertoca.gfi.service.PessoaServiceTest
> [INFO] Provider - Extra PersistenceUnitInfo properties: null
> [DEBUG] Configuration - added domain: metadataPU
> [INFO] InstrumentingUnit - *** Adding transformer: org.apache.cayenne.jpa.instrument.UnitClassTransformer@1abcc03
> Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.729 sec <<< FAILURE!
> ilberto@ti-des05:~/dev/netbeans-config/workspace/gfi/core> cat target/surefire-reports/com.gilbertoca.gfi.service.PessoaServiceTest.txt
> -------------------------------------------------------------------------------
> Test set: com.gilbertoca.gfi.service.PessoaServiceTest
> -------------------------------------------------------------------------------
> Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.73 sec <<< FAILURE!
> hello(com.gilbertoca.gfi.service.PessoaServiceTest)  Time elapsed: 0.681 sec  <<< ERROR!
> javax.persistence.PersistenceException: No Persistence provider for EntityManager named metadataPU: Provider named org.apache.cayenne.jpa.Provider threw unexpected exception at create EntityManagerFactory:
> java.lang.IllegalStateException
> java.lang.IllegalStateException: Attempt to add a transformer failed - instrumentation is not initialized.
>         at org.apache.cayenne.jpa.instrument.InstrumentingUnit.addTransformer(InstrumentingUnit.java:69)
>         at org.apache.cayenne.jpa.Provider.createContainerEntityManagerFactory(Provider.java:243)
>         at org.apache.cayenne.jpa.Provider.createEntityManagerFactory(Provider.java:194)
>         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
>         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
>         at com.gilbertoca.gfi.service.PessoaServiceTest.setUp(PessoaServiceTest.java:32)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

The interesting thing is that while using the old method
(maven-surefire-plugin) to enhance the POJOs and using just the
metadataPU persistence unit, the cayenne jpa try to enhance classes that
don't exists on that persistence unit:
> [INFO] Building jar: /tmp/surefirebooter6241.jar
> *** CayenneAgent starting...
> 
> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Running com.gilbertoca.gfi.service.PessoaServiceTest
> [INFO] Provider - Extra PersistenceUnitInfo properties: null
> [DEBUG] Configuration - added domain: metadataPU
> [INFO] InstrumentingUnit - *** Adding transformer: org.apache.cayenne.jpa.instrument.UnitClassTransformer@3ae941
> [INFO] UnitClassTransformer - Will transform managed class: com/gilbertoca/gfi/model/inventario/Item
> [INFO] Enhancer - enhancing class com/gilbertoca/gfi/model/inventario/Item
> [INFO] UnitClassTransformer - Will transform managed class: com/gilbertoca/gfi/model/inventario/UnidadeMedida
> [INFO] Enhancer - enhancing class com/gilbertoca/gfi/model/inventario/UnidadeMedida
> [INFO] UnitClassTransformer - Will transform managed class: com/gilbertoca/gfi/model/inventario/Produto
> [INFO] Enhancer - enhancing class com/gilbertoca/gfi/model/inventario/Produto
> Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.075 sec <<< FAILURE!

> -------------------------------------------------------------------------------
> Test set: com.gilbertoca.gfi.service.PessoaServiceTest
> -------------------------------------------------------------------------------
> Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.074 sec <<< FAILURE!
> hello(com.gilbertoca.gfi.service.PessoaServiceTest)  Time elapsed: 1.008 sec  <<< ERROR!
> javax.persistence.PersistenceException: No Persistence provider for EntityManager named metadataPU: Provider named org.apache.cayenne.jpa.Provider threw unexpected exception at create EntityManagerFactory:
> java.lang.IllegalArgumentException
> java.lang.IllegalArgumentException: Null id Produto.cd_produto
>         at org.apache.cayenne.jpa.bridge.DataMapConverter$JpaJoinColumnVisitor.onStartNode(DataMapConverter.java:454)
>         at org.apache.cayenne.util.TraversalUtil.traverse(TraversalUtil.java:92)
>         at org.apache.cayenne.util.TraversalUtil.traverse(TraversalUtil.java:113)
>         at org.apache.cayenne.util.TraversalUtil.traverse(TraversalUtil.java:113)
>         at org.apache.cayenne.util.TraversalUtil.traverse(TraversalUtil.java:118)
>         at org.apache.cayenne.util.TraversalUtil.traverse(TraversalUtil.java:113)
>         at org.apache.cayenne.util.TraversalUtil.traverse(TraversalUtil.java:80)
>         at org.apache.cayenne.jpa.bridge.DataMapConverter.toDataMap(DataMapConverter.java:95)
>         at org.apache.cayenne.jpa.Provider.createContainerEntityManagerFactory(Provider.java:248)
>         at org.apache.cayenne.jpa.Provider.createEntityManagerFactory(Provider.java:194)
>         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
>         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
>         at com.gilbertoca.gfi.service.PessoaServiceTest.setUp(PessoaServiceTest.java:32)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)


Gilberto

Re: jpa provider

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

On Jan 3, 2008, at 5:09 AM, Andrus Adamchik wrote:

>
> On Jan 2, 2008, at 10:02 PM, Gilberto C Andrade wrote:
>
>>> <phase>process-classes</phase>
>>>   <configuration>
>>>                                    <tasks>
>>>                                        <java  
>>> classname="org.apache.cayenne.enhancer.Enhancer"
>>>                                               
>>> classpathref="maven.runtime.classpath"
>>>                                              dir="target/classes"  
>>> fork="true" />
>>>                                    </tasks>
>>>                                </configuration>
>
> This certainly won't work cause there's no such ant task in  
> Cayenne. OpenJPA in this example seems to be doing the enhancement  
> right after compilation instead of runtime.

OpenJPA can run in multiple modes:

1. Enhance as part of building the application's jar file. There are  
Eclipse, ant, and maven plugins for this purpose (sure about the  
maven part; not as sure about the Eclipse and ant plugins)
2. Enhance during class loading via Java agent specified on the java  
command line
3. Enhance during deployment class loading via Java EE integration  
callback
4. Don't enhance but use reflection at runtime.

Craig

> We will likely provide a similar task at some point, but this  
> shouldn't really change how enhancer operates (i.e. if it has bugs,  
> those won't go away if we do enhancement at a different point).
>
> Andrus

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: jpa provider

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jan 2, 2008, at 10:02 PM, Gilberto C Andrade wrote:

>> <phase>process-classes</phase>
>>   <configuration>
>>                                    <tasks>
>>                                        <java  
>> classname="org.apache.cayenne.enhancer.Enhancer"
>>                                               
>> classpathref="maven.runtime.classpath"
>>                                              dir="target/classes"  
>> fork="true" />
>>                                    </tasks>
>>                                </configuration>

This certainly won't work cause there's no such ant task in Cayenne.  
OpenJPA in this example seems to be doing the enhancement right after  
compilation instead of runtime. We will likely provide a similar task  
at some point, but this shouldn't really change how enhancer operates  
(i.e. if it has bugs, those won't go away if we do enhancement at a  
different point).

Andrus