users@glassfish.java.net

Re: ClassCastException when using JPA result (spring 2.5)

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Wed, 20 Aug 2008 14:49:17 -0400

I made two changes:

1) set tansaction-type="JTA"
2) Removed my <class></class> line and replaced it with
<exclude-unlisted-classes>false</exclude-unlisted-classes>

I don't get the EJBClassLoader exception anymore, but when I try to use
my entity I get a different exception:

> java.lang.IllegalArgumentException: Object: key=[ryanTest] value=[test value] is not a known entity type.
It used my entitiy's .toString method which output the key/value in the
exception's message. Anyhow, I have no clue why Spring 2.5.5 works for
you with JPA in GlassFish V2 UR2 but not for me. Obviously there are
class loading problems, and I hope someone from Sun jumps in to help.


Thanks,
Ryan



Manfred Riem wrote:
> My persistence.xml file looks like this.
>
> <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="myname" transaction-type="JTA">
> <provider>oracle.toplink.essentials.PersistenceProvider</provider>
> <jta-data-source>jdbc/myname</jta-data-source>
> <exclude-unlisted-classes>false</exclude-unlisted-classes>
> </persistence-unit>
> </persistence>
>
> Manfred
>
> -----Original Message-----
> From: Ryan de Laplante [mailto:ryan_at_ijws.com]
> Sent: Wednesday, August 20, 2008 12:15 PM
> To: users_at_glassfish.dev.java.net
> Subject: Re: ClassCastException when using JPA result (spring 2.5)
>
> Thanks for your help. Do you have Spring 2.5.5 working on GlassFish V2
> UR2 using the built in TopLink Essentials as a JPA provider? I tried
> your suggestion and still get the EJBClassLoader exception. I noticed
> that at some point I removed the PersistenceAnnotationBeanPostProc
> line. I was hoping that was going to fix my problem. Here is what I
> have now:
>
> /WEB-INF/applicationContext.xml
>
> <bean
> class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProc
> essor"/>
> <tx:annotation-driven/>
>
> <bean id="dataSource"
> class="org.springframework.jndi.JndiObjectFactoryBean">
> <property name="jndiName" value="jdbc/test"/>
> </bean>
>
> <bean id="entityManagerFactory"
> class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
> <property name="dataSource" ref="dataSource"/>
> <property name="jpaVendorAdapter">
> <bean
> class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"/>
> </property>
> <property name="loadTimeWeaver">
> <bean
> class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTi
> meWeaver"/>
> </property>
> </bean>
>
> <bean id="transactionManager"
> class="org.springframework.orm.jpa.JpaTransactionManager">
> <property name="entityManagerFactory" ref="entityManagerFactory" />
> </bean>
>
>
> persistence.xml
>
> <persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
> <provider>oracle.toplink.essentials.PersistenceProvider</provider>
> <class>com.example.dao.SystemSettingEntity</class>
> </persistence-unit>
>
>
> My JPA entities are inside the .war file. Where are yours? Is the
> overall project inside an EAR?
>
> I read that Hibernate doesn't need a load time weaver. I'm probably
> going to try using Hibernate + Entity Manager as my JPA provider next.
> I've spent 3 days on this so far, hopefully I will be successful before
> the end of the day :)
>
>
> Thanks,
> Ryan
>
>
>
> Manfred Riem wrote:
>
>> No not true ;)
>>
>> <bean
>>
>>
> class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProc
>
>> essor"/>
>>
>> <bean id="entityManagerFactory"
>>
>>
> class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
>
>> <property name="jpaVendorAdapter">
>> <bean
>> class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"/>
>> </property>
>> <property name="dataSource" ref="dataSource"/>
>> <property name="loadTimeWeaver">
>> <bean
>>
>>
> class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTi
>
>> meWeaver"/>
>> </property>
>> </bean>
>>
>> This should do the trick with Spring 2.5.5
>>
>> Manfred
>>
>> -----Original Message-----
>> From: Ryan de Laplante [mailto:ryan_at_ijws.com]
>> Sent: Wednesday, August 20, 2008 9:45 AM
>> To: users_at_glassfish.dev.java.net
>> Subject: Re: ClassCastException when using JPA result (spring 2.5)
>>
>> Since I want to use Spring for my DAO I put the project back the way it
>> was and did some more googling. I found that there is a Load Time
>> Weaver for Glassfish so I updated this part of the entityManagerFactory
>> bean:
>>
>> <property name="loadTimeWeaver">
>> <bean
>>
>>
> class="org.springframework.instrument.classloading.glassfish.GlassFishLoadTi
>
>> meWeaver"/>
>> </property>
>>
>> That creates a new problem. It can't find my entity class when
>> initializing JPA. The deepest part of the exception reveals that it is
>> trying to use the EJBClassLoader, and since I am not using EJB (it's a
>> .war project) I guess it is not finding it.
>>
>> Caused by: java.lang.ClassNotFoundException:
>> com.example.dao.SystemSettingEntity
>> at
>>
>>
> com.sun.enterprise.loader.EJBClassLoader.findClassData(EJBClassLoader.java:7
>
>> 18)
>> at
>>
>>
> com.sun.enterprise.loader.EJBClassLoader$DelegatingClassLoader.findClass(EJB
>
>> ClassLoader.java:1380)
>> at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>> at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
>> at
>>
>>
> oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.isEn
>
>> tity(PersistenceUnitProcessor.java:316)
>>
>> Here's another thread about that problem:
>> http://forum.springframework.org/showthread.php?t=30954
>>
>> I'm starting to get the impression that the only way to use Spring on
>> GlassFish to manage JPA is if I create an EJB project and put my
>> entities in there. That can't be true, is it?
>>
>>
>> Thanks,
>> Ryan
>>