Problem with Gilead Integration in GWT, Spring and JPA

299 views
Skip to first unread message

marky8264

unread,
Mar 24, 2011, 10:50:47 AM3/24/11
to Google Web Toolkit
hey,
I'm a newbie with these frameworks. Firstly i want to write a small
web app with gwt for the frontend, spring for backend and jpa for the
persistence operations. I use Hibernate as JPA implementation.

I started with a simple construction (2 simply entities, 2 DAO,1
remote service). I have no problems with this example. After i had
extended the entities with lists, i got some problems with the lazy
loading and serialization. Therefore i searched for solution and found
the Gilead Framework.

Now i have following problem:
org.hibernate.LazyInitializationException: failed to lazily initialize
a collection of role: <list attribute of my class>, no session or
session was closed
at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:
383)
at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:
375)

I don't understand the problem, because i marked the service method
with @Transactional(propagation=Propagation.NESTED, readOnly=true).
What is the cause of my problem?
thanks in advance

Paul Robinson

unread,
Mar 24, 2011, 1:31:34 PM3/24/11
to google-we...@googlegroups.com
Your collection is mapped as lazy, which means hibernate will load data on demand rather than up-front. However, you then try and access the collection outside a hibernate session, so it cannot do the load.

You should either load what you need inside the hibernate session, or make your collection be non-lazy.

marky8264

unread,
Mar 24, 2011, 1:51:41 PM3/24/11
to Google Web Toolkit
thanks for your answer.
However, if i use a eager loading for the list, i will get this:
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type
'org.hibernate.collection.PersistentBag' was not included in the set
of types which can be serialized by this SerializationPolicy or its
Class object could not be loaded. For security purposes, this type
will not be serialized.: instance = []
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:
614)
at
com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:
126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter
$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:
534)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:
704)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:
734)
at
com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:
616)
at
com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:
126)
at
com.google.gwt.user.client.rpc.core.java.util.Map_CustomFieldSerializerBase.serialize(Map_CustomFieldSerializerBase.java:
52)
at
com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer.serialize(HashMap_CustomFieldSerializer.java:
38)
... 76 more

Although i use Gilead, i get this exception. I thought that Gilead
will clone the entity object and replace the hibernate collections
with normal collections.
Why do i get this exception?

Is it possible that this is the reason:
[...]
24 Mär 2011 16:43:38,695 DEBUG PersistentBeanManager: Not persistent
object, merge is not needed : 1
24 Mär 2011 16:43:38,696 DEBUG GileadRPCHelper: Merge took 92 ms.
24 Mär 2011 16:43:38,979 TRACE HibernateUtil : Exception during
getCurrentSession
org.hibernate.HibernateException: No Hibernate Session bound to
thread, and configuration does not allow creation of non-transactional
one here
at
org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:
63)
at
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:
700)
at
net.sf.gilead.core.hibernate.HibernateUtil.getCurrentSession(HibernateUtil.java:
1829)
at
net.sf.gilead.core.hibernate.HibernateUtil.flushIfNeeded(HibernateUtil.java:
975)
at
net.sf.gilead.core.PersistentBeanManager.clone(PersistentBeanManager.java:
227)
at
net.sf.gilead.gwt.GileadRPCHelper.parseReturnValue(GileadRPCHelper.java:
157)
[...]

Here my gilead config:
<bean id="proxySerializer"
class="net.sf.gilead.core.serialization.GwtProxySerialization" />

<bean id="proxyStore"
class="net.sf.gilead.core.store.stateless.StatelessProxyStore">
<property name="proxySerializer" ref="proxySerializer" />
</bean>

<bean id="persistenceUtil"
class="net.sf.gilead.core.hibernate.jpa.HibernateJpaUtil">
<property name="entityManagerFactory" ref="entityManagerFactory" /
>
</bean>

<bean id="persistentBeanManager"
class="net.sf.gilead.core.PersistentBeanManager">
<property name="proxyStore" ref="proxyStore" />
<property name="persistenceUtil" ref="persistenceUtil" />
</bean>

Paul Robinson

unread,
Mar 25, 2011, 5:46:02 AM3/25/11
to google-we...@googlegroups.com
I use DTOs rather than Gilead...I guess the gilead forums may be able to help.

> 24 M�r 2011 16:43:38,695 DEBUG PersistentBeanManager: Not persistent


> object, merge is not needed : 1

> 24 M�r 2011 16:43:38,696 DEBUG GileadRPCHelper: Merge took 92 ms.
> 24 M�r 2011 16:43:38,979 TRACE HibernateUtil : Exception during

marky8264

unread,
Mar 25, 2011, 8:23:08 AM3/25/11
to Google Web Toolkit
However, this is a lot of work or?
You must create one DTO for one entity. If you have a lot of entites,
it will be a lot of work.
Is there another possibility to solve this serialization problem?
> > 24 M�r 2011 16:43:38,695 DEBUG PersistentBeanManager: Not persistent
> > object, merge is not needed : 1
> > 24 M�r 2011 16:43:38,696 DEBUG GileadRPCHelper: Merge took 92 ms.
> > 24 M�r 2011 16:43:38,979 TRACE HibernateUtil  : Exception during

gperetin

unread,
Mar 25, 2011, 2:08:39 PM3/25/11
to Google Web Toolkit
From the output above, seems like you're missing @Transactional (or
XML configuration if thats what you're using) on one of your methods
that access database.

However, I would recommend you cheking out MyBatis data mapper (if
that's an option for you), I started using it recently instead of
Hibernate and found it much simpler. You do need to write some SQL
though... With MyBatis you don't have to use Gilead at all since it
returns plain POJOs that can be serialized, unlike Hibernate that
wraps POJOs.

Goran
Reply all
Reply to author
Forward
0 new messages