users@glassfish.java.net

Re: ClassCastException when using JPA result

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Wed, 20 Aug 2008 10:45:15 -0400

The people in the Spring forums could only offer this advice:

> You must be loading the classes twice, either they are on the
> classpath twice, or you are (re)loading those things in different
> servlets/listeners/applications and try to share them.

Since I am really really stuck right now, I have created a sample
project and attached it to this email. It is a Maven2 project created in
NetBeans 6.1 for use with GlassFish V2 UR2

- Web app, JSF/Facelets
- JPA (TopLink Essentials provider)
- Spring 2.5
- The one and only facelet page invokes a test method on a session
scoped managed bean (resolved by Spring).
- The session scoped managed bean has a DAO injected into it
- The test method in the session scoped mbean invokes a getProperty
method on the DAO
- The DAO uses Spring's @Transactional and @PersistenceContext to inject
a JPA persistence unit and use transactions. It runs a basic query,
then gets a ClassCastException when trying to use the result.

It is set up to use a postgres database on localhost port 5432,
username=postgres password=postgres You'll need to run a few queries
to set it up:

CREATE DATABASE test WITH OWNER = postgres ENCODING = 'UTF8';

CREATE TABLE system_settings ("key" character varying(255) NOT NULL,
"value" character varying(255) NOT NULL, CONSTRAINT
system_settings_pkey PRIMARY KEY (key)) WITH (OIDS=FALSE);

ALTER TABLE system_settings OWNER TO postgres;

INSERT INTO system_settings("key", "value") VALUES ('systemLogLevel',
'DEBUG');



This is an extremely bare bones basic example of using JPA with Spring.
Can someone please point out how there are multiple ClassLoaders and
help me move forward in my project?



Thanks,
Ryan


Ryan de Laplante wrote:
> Thank you for responding. Based on what I pasted in the forum post
> (see link), what am I doing wrong?
> I see the bean defs for entityManagerFactory:
>
> <property name="loadTimeWeaver">
> <bean
> class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver"/>
>
> </property>
>
> This is the first time I try to use JPA with Spring.
>
>
> Thanks,
> Ryan
>
>
> Marina Vatkina wrote:
>> Ryan,
>>
>> This is usually caused by weaving. If you have your entities weaved
>> on the server (e.g. to support LAZY loading), you need to have them
>> weaved either dynamically (ACC would do that) or statically (i.e.
>> you'd need to modify/repackage the client side jar) yourself.
>>
>> Regards,
>> -marina
>>
>> Ryan de Laplante wrote:
>>> I loading a JPA entity from my POJO DAO that uses
>>> @PersistenceContext and @Transactional from Spring 2.5. The result
>>> that is returned has the same name (ex:
>>> com.company.app.dao.SettingsEntity) but I get a class cast
>>> exception when I try to cast from Object to the entity bean class so
>>> that I can use it. I wrote more details here:
>>>
>>> http://forum.springframework.org/showthread.php?t=58964
>>>
>>> I'm wondering if this is a JPA issue, not Spring?
>>>
>>>
>>> Thanks,
>>> Ryan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>