Announcement Announcement Module
Collapse
No announcement yet.
Spring + Hibernate + lazy loading = impossible? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + Hibernate + lazy loading = impossible?

    (I have had a minor discussion here but since this is a more generell question I posted it in a new thread.)

    I am writing an Eclipse Rich Client application using Spring and Hibernate for database handling. I have managerobjects looking a little bit like this:

    Code:
    public interface BarManager {
            public void setAuditService(IAuditService auditService);
    	public Collection<Bar> getAllBars();
    	public long createBar(String barName, double barData);
    	public void edit(Bar bar);	
    	public void delete(Bar bar);	
    	public Folder getBar( long id );	
    }
    The create, edit and delete methods are declared and handled as transactions by Spring. This works fine. However the get methods should load objects that support lazy-loading. This seems to be impossible to get to work satisfying.

    If I declare the get methods as transactions Spring of course closes the sessions after the methods have been executed and thus no lazy-loading.

    When I don't declare them as transactions at all each time a get method is called a new session and database connection is tied up. This is almost what I want because now the lazy loading works. However database connections are a limited resource and I tend to run out of them...

    I have a tree view that should support partial reloading. Since loading things from the database takes like forever I do this in a separate thread. So each call to the get methods is performed in a separate thread. Since I have been told that sessions isn't thread safe I guess I can't share one (always open) session for the lazy loading among these different threads either.

    This seems totally unsolvable as far as I can see. Should I just forget about lazy loading?
Working...
X