Cached plugin and could not initialize proxy - no Session

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Cached plugin and could not initialize proxy - no Session

NiBe
This post was updated on .
Hi all,
I'm an happy user of Cache Plugin, and I use it with grails 2.2.1.
Here my environment:

    Grails 2.2.1
    MySQL 5.5
    CentOs 6.3
    cache-1.0.1 plug-in

It seems that after a couple of days, but sometimes even before, I got this problem:

could not initialize proxy - no Session. Stacktrace follows:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session

I narrow it down and the reason, I believe, is that the system cannot fetch all the info in the query when there are involved one-to-many relation. I use also cache plug-in so I can store the query for a faster fetch. I temporary fix the issue, anytime the problem appears I clear the cache, so I force the system to do the query again and everything works fine.

But as you can image I wish to avoid this behavior and find a more elegant solution without manual intervention. I discard the option to disable lazy fetch, I need it.
I use the attach method to refresh the list, as some other post suggest, and it works, but honestly I'm not satisfied with the solution. I use cache plug in the collect data in a faster way, as example:

    def listCurrency = cachedQueryService.currencyList()

In the line of code a retrieve a list of currency object, so I have to loop this list and for each items do an attach() method. And I have to do this every time to avoid the org.hibernate.LazyInitializationException: could not initialize proxy - no Session error. And it doesn't seems to me a good idea.

Any suggest? Please I'm going mad about this

thanks a lot

NiBE

Reply | Threaded
Open this post in threaded view
|

Re: Cached plugin and could not initialize proxy - no Session

NiBe
Hi,
any clue about this? I'm really going mad.

NiBE
Reply | Threaded
Open this post in threaded view
|

Re: Cached plugin and could not initialize proxy - no Session

lucastex
wow,

the same getting me for the last week...

haven't investigated deeply yet, but any help would be great

[]s, 



On Wed, May 8, 2013 at 1:33 PM, NiBe <[hidden email]> wrote:
Hi,
any clue about this? I'm really going mad.

NiBE



--
View this message in context: http://grails.1312388.n4.nabble.com/Cached-plugin-and-could-not-initialize-proxy-no-Session-tp4644462p4644547.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Cached plugin and could not initialize proxy - no Session

NiBe
Hi,
yes it's a real mess, and I still don't know how to fix it. I schedule to reset the cache every night, but as workaround it works but I still get the issue, even if less often.
I hope some one have find a good solution


Reply | Threaded
Open this post in threaded view
|

Re: Cached plugin and could not initialize proxy - no Session

lucastex
Have you identified when it occurs? 
For example, only when the cache is empty for that entry, or when the cache already have the entry and some other condition occurs, etc...

I haven't, but after the first cache timeout, get normal back.

:/



On Thu, May 9, 2013 at 3:55 AM, NiBe <[hidden email]> wrote:
Hi,
yes it's a real mess, and I still don't know how to fix it. I schedule to
reset the cache every night, but as workaround it works but I still get the
issue, even if less often.
I hope some one have find a good solution






--
View this message in context: http://grails.1312388.n4.nabble.com/Cached-plugin-and-could-not-initialize-proxy-no-Session-tp4644462p4644572.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Cached plugin and could not initialize proxy - no Session

NiBe
Hi,
basically it's random, I guess.
The cache is already filled up, but when I try to access to a value that belong to a relation one-to-many is not attach so it goes in error, of course if I do a attach() method it works, but it's not a feasible solution.
If after it occurs, I clean the cache, even at runtime, then it works again.
Reply | Threaded
Open this post in threaded view
|

Re: Cached plugin and could not initialize proxy - no Session

NiBe
Hi there,
I use this workaround, which of course doesn't satisfay me.
First I did something like this everytime I have to access to a cached query:
 
 def checkRecordAttached(List item) {
         for (i in item) {
             if (!i.isAttached()) {
                 i.attach()
             }
         }
        return item
    }

But then I realize that once the cached list is deattach it will always go trough the loop, so I decide as soon as I detect that is detach I just delete the cached and do again the query so this work and is a bit better than the one before.
if anyone has a better solution please let me know.

thanks