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:15:16 -0400

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.PersistenceAnnotationBeanPostProcessor"/>
<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.GlassFishLoadTimeWeaver"/>
    </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
>