-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Lazy loading, EntityManager and concurrency.
PostPosted: Sat Sep 05, 2009 12:26 pm 
Newbie

Joined: Sat Sep 05, 2009 12:22 pm
Posts: 1
I need advice which strategy to use with lazy loading.

My project is based on Spring, Struts 2 and Hibernate JPA. I have enough OneToMany and ManyToMany relationships and it's reasonable to use lazy loading. It seems very convenient to load data in Struts Actions with OpenEntityManagerInViewFilter in such way like:

Code:
Style style = user.getStyle()


But to avoid LazyLoadException I have to use:

Code:
@PersistenceContext(type=PersistenceContextType.EXTENDED)


Unfortunately, EntityManager in this case becomes not thread-safe, according to Spring docs: "Extended EntityManagers are not thread-safe, hence they must not be used in concurrently accessed beans (which Spring-managed singletons usually are)." EXTENDED means that EntityManager is shared in user session and my EntityManager is injected in singleton services.

I've found this issue when tried to make quick sequential page reloading which call some selects and got:

Code:
java.sql.SQLException: You can't operate on a closed Statement!!!


What's the best practice in this situation:

1. Try synchronize session access to EntityManager by myself or put each user database requests in separate queue (something terrible I suppose).

2. Use HQL queries with join fetch to preload data for access outside of transaction (maybe overhead).

3. Or something else???

And why we need EXTENDED context if it's so unreliable??

Thanks for help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.