-->
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.  [ 4 posts ] 
Author Message
 Post subject: Lazy initialization with JPA
PostPosted: Thu Jan 31, 2008 1:26 pm 
Newbie

Joined: Wed Aug 01, 2007 6:08 pm
Posts: 13
I am using Hibernate 3.0 with JPA and Spring 2.0. I am using annotations to declare transactions, e.g.

@Transactional (propagation = Propagation.REQUIRED, readOnly = true)
public Collection<DataPoint> findDailyData(DataPointSpecification spec) {
return dataPointDao.findDailyData(spec);
}


And inside my model, I am using annotations to define relationships, e.g.
*/
@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
@JoinColumn(name = "DATA_ELEMENT_ID", insertable=true, updatable=true)
public DataElement getDataElement() {
return this.dataElement;
}


However, when I try to access these relationships outside transaction, I get session closed exception. How do I define lazy associations in this case (other than making them eager).

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Lazy initialization with JPA
PostPosted: Thu Jan 31, 2008 3:31 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
You will have to access the property within the scope of the same transaction. It will have the same effect as eager fetching in this use case but at lease you can use the lazy fetching in other use cases.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 3:39 pm 
Newbie

Joined: Wed Aug 01, 2007 6:08 pm
Posts: 13
I know it works within same transaction, but I need lazy initialization outside transaction sort of similar to storing session in thread local.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 3:50 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
bhatti_shahzad wrote:
I know it works within same transaction, but I need lazy initialization outside transaction sort of similar to storing session in thread local.


I really doubt if there is any such solution since it can cause serious scaling problems but at the same time I might not be fully aware of all solutions. We can wait to see if anyone else has a novel idea.


Farzad-


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

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.