-->
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.  [ 38 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: confusion about the "lazy" attribute
PostPosted: Mon Feb 14, 2005 4:38 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
I have confusion about the lazy attribute:
It looks like the lazy attribute can be applied to multiple places, and can also be used along with the "fecth" attribute. Is there are definative guide that explains how to use it.

I have question wrt to:

lazy on class level
lazy on many-to-one

etc

And how does it play with the "fetch" attribute

also read this post: http://forum.hibernate.org/viewtopic.php?t=938799

-Jennifer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 2:54 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Quote:
lazy on class level


At the class level, this is referring to proxies for lazy initialization. See: http://www.hibernate.org/hib_docs/refer ... ce-proxies

Quote:
lazy on many-to-one


I think you are trying to refer to collections, so this should be one-to-many as opposed to many-to-one. It would only be a lazy association should the many-to-one object be proxied.

For information on lazy collections, see: http://www.hibernate.org/hib_docs/refer ... tions-lazy

I suggest purchasing a copy of Hibernate in Action if these topics still aren't clear.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 2:56 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
On many-to-one comment:

My bad, I thought you were referring to Hibernate 2.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all this is very easier in H3.

By default, "all" is lazy
so just set fetch attribute:
- by default fetch = "select"--> lazy behaviour
- you can force fetch="join" --> eager fetching by default

Easy ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: still get the error - i feel like a ....
PostPosted: Tue Feb 15, 2005 5:13 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
What am I doign wrong here. Duh !!

Mapping

<hibernate-mapping .....>
<class name="BankActlEstStatHist" table="TBANK_ACTL_EST_STAT_HIST" >
..........................................................
<many-to-one
class="foobarinc.estimate.BankActlEstStatType"
name="bankActlEstStatTypeCde"
not-null="true"
fetch="join">
<column name="BANK_ACTL_EST_STAT_TYPE_CDE" />
</many-to-one>
..............................................
</class>
</hibernate-mapping>

I still get the error

Error log stack trace

2005-02-15 15:51:04,531 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.engine.CollectionLoadContext - creating collection wrapper:[foobarinc.estimate.BankActlEstStatHist.tbankActlEstSet#222]
2005-02-15 15:51:04,531 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.engine.TwoPhaseLoad - done materializing entity [foobarinc.estimate.BankActlEstStatHist#222]
2005-02-15 15:51:04,531 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.engine.PersistenceContext - initializing non-lazy collections
2005-02-15 15:51:04,531 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.impl.SessionImpl - closing session
2005-02-15 15:51:04,531 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.impl.SessionImpl - disconnecting session
2005-02-15 15:51:04,531 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.jdbc.AbstractBatcher - closing JDBC connection (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)
2005-02-15 15:51:04,547 [Servlet.Engine.Transports : 1] DEBUG org.hibernate.impl.SessionImpl - after transaction completion
2005-02-15 15:51:05,281 [Servlet.Engine.Transports : 1] ERROR org.hibernate.LazyInitializationException - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:80)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:133)
at foobarinc.estimate.BankActlEstStatType$$EnhancerByCGLIB$$aa8325ea.getBankActlEstStatTypeDesc(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:1185)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:772)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:1008)
at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:227)
at org.apache.jsp._pgBankView._jspService(pgBankView.jsp :192)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:344)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.serviceJspFile(JspServlet.java:683)
at com.ibm.ws.webcontainer.jsp.servlet.JspServlet.service(JspServlet.java:781)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1014)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.ServicingServletState.service(StrictLifecycleServlet.java:333)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1014)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:388)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
at kpmg.taxshared.beans.navigation.SessionFilter.doFilter(SessionFilter.java:124)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1010)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:592)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:204)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:125)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:286)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:615)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:449)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:912)

Thanks
Jennifer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 6:03 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about generated sql?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: generated sql
PostPosted: Tue Feb 15, 2005 6:15 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
select bankactles0_.BANK_ACTL_EST_STAT_HIST_ID as BANK1_, bankactles0_.FISCAL_YR as FISCAL2_13_, bankactles0_.BANK_ACTL_EST_STAT_ADD_DT as BANK3_13_, bankactles0_.BANK_ACTL_EST_STAT_CMNT as BANK4_13_, bankactles0_.BANK_ACTL_EST_STAT_ADD_ID as BANK5_13_, bankactles0_.QTR_NBR as QTR6_13_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK7_13_, bankactles0_.BANK_ID as BANK8_13_ from TBANK_ACTL_EST_STAT_HIST bankactles0_ where (bankactles0_.BANK_ID=? ) order by bankactles0_.BANK_ACTL_EST_STAT_ADD_DT

Here ya go sir

- Jennifer


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 7:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
so how are you retreiving these? Session.load()? HQL?


Top
 Profile  
 
 Post subject: works with this - but leaves me comlpetely confused
PostPosted: Tue Feb 15, 2005 7:13 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
If I change the mapping for the "BankActlEstStatType" object and add the lazy=false this works. But why ???? Do I need to do this. I can tget the logic for this. Can you please help and explain.

<hibernate-mapping package="foobarinc.estimate">
<class name="BankActlEstStatType" table="TBANK_ACTL_EST_STAT_TYPE" lazy="false">
<id..........................
..................
</class>
</hibernate-mapping>

I thought setting the fetch=join in "BankActlEstStatHist" should suffice.

hmmm

- Jennifer


Top
 Profile  
 
 Post subject: code between sessions
PostPosted: Tue Feb 15, 2005 7:15 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
Code to retrive....

Session sess = createSession();
estHist =
(ArrayList) sess.createQuery(
"FROM BankActlEstStatHist as bankActlEstStatHist WHERE bankActlEstStatHist.bank.id = ? order by bankActlEstStatHist.bankActlEstStatAddDt")
.setParameter(0, bankId, Hibernate.INTEGER).list();
sess.close();


Top
 Profile  
 
 Post subject: SQL generated ..
PostPosted: Tue Feb 15, 2005 7:30 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
Morever Although the fetch="join" (and lazy='false' - although I dont knwo why I need that on the lookup object) I see 2 selects in the sql.
I was hoping to see an outer - join. do I need to do something else ?

-Jennifer

SQL generated:

[2/15/05 17:35:28:438 EST] 6b727efa SystemOut O Hibernate: select bankactles0_.BANK_ACTL_EST_STAT_HIST_ID as BANK1_, bankactles0_.FISCAL_YR as FISCAL2_13_, bankactles0_.BANK_ACTL_EST_STAT_ADD_DT as BANK3_13_, bankactles0_.BANK_ACTL_EST_STAT_CMNT as BANK4_13_, bankactles0_.BANK_ACTL_EST_STAT_ADD_ID as BANK5_13_, bankactles0_.QTR_NBR as QTR6_13_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK7_13_, bankactles0_.BANK_ID as BANK8_13_ from TBANK_ACTL_EST_STAT_HIST bankactles0_ where (bankactles0_.BANK_ID=? ) order by bankactles0_.BANK_ACTL_EST_STAT_ADD_DT
[2/15/05 17:35:28:484 EST] 6b727efa SystemOut O Hibernate: select bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK1_0_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_DESC as BANK2_14_0_ from TBANK_ACTL_EST_STAT_TYPE bankactles0_ where bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE=?
[2/15/05 17:35:28:484 EST] 6b727efa SystemOut O Hibernate: select bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK1_0_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_DESC as BANK2_14_0_ from TBANK_ACTL_EST_STAT_TYPE bankactles0_ where bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE=?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 8:06 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Jennifer,

Hibernate lazy mechanism is far from being perfect. I was using it a lot and that's the fact. I guess you will have to live with that if you plan to use lazy with Hibernate. Better avoid it.

HTH.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 8:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
HQL queries ignore the fetch-settings in the mapping - you can use the fetch keywords to do eager fetching there.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 10:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Jennifer, this stuff is better documented in HiA than in the HB2.1 user guide. It should all make perfect sense after reading the book.

The HB3 user guide is much improved, but HB3 has different (better) defaults.


Top
 Profile  
 
 Post subject: here's what I ended up doing
PostPosted: Wed Feb 16, 2005 12:33 pm 
Beginner
Beginner

Joined: Thu Jan 27, 2005 6:31 pm
Posts: 21
Location: This Life - Planet Earth
Thanks Gavin;
Heres what I did now...

1> Read HiA. And here's what I understood.
2> Mapping for the main object

<hibernate-mapping package="foobarinc.estimate">
<class name="BankActlEstStatHist" table="TBANK_ACTL_EST_STAT_HIST">
........................
<many-to-one
class="foobarinc.estimate.BankActlEstStatType"
name="bankActlEstStatTypeCde"
not-null="true"
fetch="join"
outer-join="true"

>
<column name="BANK_ACTL_EST_STAT_TYPE_CDE" />
</many-to-one>
----------------------
</class>
</hibernate-mapping>

3> Mapping for the lookup (associated) object

<hibernate-mapping package="foobarinc.estimate">
<class name="BankActlEstStatType" table="TBANK_ACTL_EST_STAT_TYPE" lazy="false">
----------------------------------
</class>
</hibernate-mapping>


Does this make sense. and now I use the same HQL as before. I still get mutiple queries being run - wonder why it is not doing a outer-join. Does something need to be specified in the global properties file ??

[2/16/05 11:13:02:078 EST] 479bf27a SystemOut O Hibernate: select bankactles0_.BANK_ACTL_EST_STAT_HIST_ID as BANK1_, bankactles0_.FISCAL_YR as FISCAL2_13_, bankactles0_.BANK_ACTL_EST_STAT_ADD_DT as BANK3_13_, bankactles0_.BANK_ACTL_EST_STAT_CMNT as BANK4_13_, bankactles0_.BANK_ACTL_EST_STAT_ADD_ID as BANK5_13_, bankactles0_.QTR_NBR as QTR6_13_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK7_13_, bankactles0_.BANK_ID as BANK8_13_ from TBANK_ACTL_EST_STAT_HIST bankactles0_ where (bankactles0_.BANK_ID=? ) order by bankactles0_.BANK_ACTL_EST_STAT_ADD_DT

[2/16/05 11:13:02:219 EST] 479bf27a SystemOut O Hibernate: select bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK1_0_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_DESC as BANK2_14_0_ from TBANK_ACTL_EST_STAT_TYPE bankactles0_ where bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE=?

[2/16/05 11:13:02:234 EST] 479bf27a SystemOut O Hibernate: select bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE as BANK1_0_, bankactles0_.BANK_ACTL_EST_STAT_TYPE_DESC as BANK2_14_0_ from TBANK_ACTL_EST_STAT_TYPE bankactles0_ where bankactles0_.BANK_ACTL_EST_STAT_TYPE_CDE=?


Thanks for you help
Jennifer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 38 posts ]  Go to page 1, 2, 3  Next

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.