Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Hibernate and lazy load

  1. #11

    Default

    Martin,

    Our domain and dao classes are being used by two applications one is a web app that uses our default mapping with lazy load. What I am working on is a command line app that needs to process every object of class A in the database (along with each associated collection).

    maxjar,

    Thanks for the link, I'll take a look.

    I think I need to do some more reading on Hibernate before I waste anymore of anyone's time.

    Thanks to everyone for the comments.

  2. #12

    Default

    Would a HibernateInterceptor be useful in this situation?

  3. #13
    Join Date
    Aug 2004
    Location
    Germany, Magdeburg
    Posts
    279

    Default

    Our domain and dao classes are being used by two applications one is a web app that uses our default mapping with lazy load. What I am working on is a command line app that needs to process every object of class A in the database (along with each associated collection).
    The reason I asked, is just that I wonder myself if it is not possible to drive the use-case 'going through the graph and analyse stuff' even further towards the domain layer? I mean you seam to do work related to the domain model. Also you are likely to have this all to appear as a business transaction (special need to control transactions). This means that it is actually appearing to be a unit of work. And transactional stuff is normally an issue for the domain layer (one layer below the UI layer).


    Cheers,

    Martin (Kersten)

  4. #14

    Default

    Ok I seem to be making some progress. Sometimes you try to make things more difficult than they need to be.

    Within a method of my DAO

    Code:
    Session session = getHibernateTemplate().getSessionFactory().openSession();
    Transaction tran = session.beginTransaction();
    
    List sites = session.find("from SiteConfig siteConfig " +
         "left join fetch siteConfig.routers router " +
         "left join fetch router.interfaces interfaces " +
         "where interfaces.monitored = ?", Boolean.TRUE, Hibernate.BOOLEAN);
    
    for &#40;int i = 0; i < sites.size&#40;&#41;; i++&#41; &#123;
         ISiteConfig siteConfig = &#40;ISiteConfig&#41; sites.get&#40;i&#41;;
         List routers = siteConfig.getRouters&#40;&#41;;
         for &#40;int j = 0; j < routers.size&#40;&#41;; j++&#41; &#123;
              IRouterConfig routerConfig =  &#40;IRouterConfig&#41; routers.get&#40;j&#41;;
              routerConfig.getInterfaces&#40;&#41;.size&#40;&#41;;
         &#125;
    &#125;
    
    tran.commit&#40;&#41;;
    session.close&#40;&#41;;
    return sites;
    I am no longer getting the LazyInitializationException. Now I need to figure out why in my test I'm getting three interfaces (two of which are null) for a given router when there is only one associated interface in the database. I guess I need to dig into Hibernate some more.

  5. #15

    Default

    In case anyone else has a similiar problem.

    I had router-interfaces mapped as a bi-directional list.

    "Please note that Hibernate does not support bidirectional one-to-many associations with an indexed collection (list, map or array) as the "many" end, you have to use a set or bag mapping."

    I changed the mapping to a bidirectional set and it works.

  6. #16
    Join Date
    Sep 2004
    Posts
    18

    Default

    Have a look at this, it explains ways to have bidirectional indexed collections:

    http://www.hibernate.org/193.html

    H3 even supports them without workarounds, also explained on that page.

  7. #17

    Default

    Thanks.

  8. #18
    Join Date
    Sep 2007
    Posts
    2

    Default An exception while query specified join fetching

    I tried to create a left join fetch of one-to-many relationship for lazy load and get an exception "query specified join fetching, but the owner of the fetched association was not present in the select list".
    The query having the exception is
    select or.orderID, or.account.customer.customerName, " +
    "or.woStatus, or.priority, or.createDate, wo.items " +
    "from Order or left join fetch or.items

    However if I query like
    from Order or left join fetch or.items

    No exception is thrown.

    What is the issue?

  9. #19
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is it possible to post the full query you are running along with the stacktrace. [code] [ /code] tags would be nice.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  10. #20
    Join Date
    Sep 2007
    Posts
    2

    Default Re: query specified join fetching exception

    The query I used is the same as posted on the above. Here is the stacktrace. Thanks.

    org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=product.items,tabl eName=item,tableAlias=item1_,origin=Order order0_,colums={order0_.OrderID, className=product.item}}] [select or.orderID, or.account.customer.customerName, or.woStatus, or.priority, or.createDate, or.items from Order or left join fetch or.items]
    org.hibernate.hql.ast.tree.SelectClause.initialize ExplicitSelectClause(SelectClause.java:195)
    org.hibernate.hql.ast.HqlSqlWalker.useSelectClause (HqlSqlWalker.java:705)
    org.hibernate.hql.ast.HqlSqlWalker.processQuery(Hq lSqlWalker.java:529)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.query(Hql SqlBaseWalker.java:645)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.selectSta tement(HqlSqlBaseWalker.java:281)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.statement (HqlSqlBaseWalker.java:229)
    org.hibernate.hql.ast.QueryTranslatorImpl.analyze( QueryTranslatorImpl.java:228)
    org.hibernate.hql.ast.QueryTranslatorImpl.doCompil e(QueryTranslatorImpl.java:160)
    org.hibernate.hql.ast.QueryTranslatorImpl.compile( QueryTranslatorImpl.java:111)
    org.hibernate.engine.query.HQLQueryPlan.<init>(HQL QueryPlan.java:77)
    org.hibernate.engine.query.HQLQueryPlan.<init>(HQL QueryPlan.java:56)
    org.hibernate.engine.query.QueryPlanCache.getHQLQu eryPlan(QueryPlanCache.java:72)
    org.hibernate.impl.AbstractSessionImpl.getHQLQuery Plan(AbstractSessionImpl.java:133)
    org.hibernate.impl.AbstractSessionImpl.createQuery (AbstractSessionImpl.java:112)
    org.hibernate.impl.SessionImpl.createQuery(Session Impl.java:1623)
    org.hibernate.ejb.AbstractEntityManagerImpl.create Query(AbstractEntityManagerImpl.java:92)
    org.jboss.ejb3.entity.TransactionScopedEntityManag er.createQuery(TransactionScopedEntityManager.java :134)
    sun.reflect.GeneratedMethodAccessor168.invoke(Unkn own Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:112)
    org.jboss.ejb3.interceptor.InvocationContextImpl.p roceed(InvocationContextImpl.java:166)
    org.jboss.ejb3.interceptor.EJB3InterceptorsInterce ptor.invoke(EJB3InterceptorsInterceptor.java:63)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.entity.TransactionScopedEntityManag erInterceptor.invoke(TransactionScopedEntityManage rInterceptor.java:54)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.AllowedOperationsInterceptor.invoke (AllowedOperationsInterceptor.java:47)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxP olicy.java:126)
    org.jboss.aspects.tx.TxInterceptor$Required.invoke (TxInterceptor.java:195)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPropagationInterceptor.invo ke(TxPropagationInterceptor.java:76)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessInstanceIntercep tor.invoke(StatelessInstanceInterceptor.java:62)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.aspects.security.AuthenticationIntercept or.invoke(AuthenticationInterceptor.java:77)
    org.jboss.ejb3.security.Ejb3AuthenticationIntercep tor.invoke(Ejb3AuthenticationInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.ENCPropagationInterceptor.invoke(EN CPropagationInterceptor.java:46)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.asynchronous.AsynchronousIntercepto r.invoke(AsynchronousInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessContainer.dynami cInvoke(StatelessContainer.java:278)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invokeL ocal(IsLocalInterceptor.java:79)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invoke( IsLocalInterceptor.java:70)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessRemoteProxy.invo ke(StatelessRemoteProxy.java:103)
    $Proxy248.query(Unknown Source)
    sun.reflect.GeneratedMethodAccessor167.invoke(Unkn own Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:281)
    org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:199)
    $Proxy249.query(Unknown Source)
    product.collectAllOrders(OrderManagerBean.java:136 )
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:112)
    org.jboss.ejb3.interceptor.InvocationContextImpl.p roceed(InvocationContextImpl.java:166)
    org.jboss.ejb3.interceptor.EJB3InterceptorsInterce ptor.invoke(EJB3InterceptorsInterceptor.java:63)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.entity.TransactionScopedEntityManag erInterceptor.invoke(TransactionScopedEntityManage rInterceptor.java:54)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.AllowedOperationsInterceptor.invoke (AllowedOperationsInterceptor.java:47)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPoli cy.java:79)
    org.jboss.aspects.tx.TxInterceptor$Required.invoke (TxInterceptor.java:191)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPropagationInterceptor.invo ke(TxPropagationInterceptor.java:76)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessInstanceIntercep tor.invoke(StatelessInstanceInterceptor.java:62)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.aspects.security.AuthenticationIntercept or.invoke(AuthenticationInterceptor.java:77)
    org.jboss.ejb3.security.Ejb3AuthenticationIntercep tor.invoke(Ejb3AuthenticationInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.ENCPropagationInterceptor.invoke(EN CPropagationInterceptor.java:46)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.asynchronous.AsynchronousIntercepto r.invoke(AsynchronousInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessContainer.dynami cInvoke(StatelessContainer.java:278)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invokeL ocal(IsLocalInterceptor.java:79)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invoke( IsLocalInterceptor.java:70)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessRemoteProxy.invo ke(StatelessRemoteProxy.java:103)
    $Proxy250.collectAllWorkOrders(Unknown Source)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:281)
    org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:199)
    $Proxy251.collectAllWorkOrders(Unknown Source)
    product.listAllOrders(ListOrderAction.java:57)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.apache.struts.actions.DispatchAction.dispatchM ethod(DispatchAction.java:270)
    org.apache.struts.actions.DispatchAction.execute(D ispatchAction.java:187)
    org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:431)
    org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:236)
    org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1196)
    org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:414)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)

Similar Threads

  1. Replies: 2
    Last Post: Dec 8th, 2005, 09:00 AM
  2. how to use hibernate lazy loading with spring transaction
    By tanmoy.chakraborty in forum Data
    Replies: 1
    Last Post: Oct 11th, 2005, 02:07 AM
  3. Hibernate and Lazy Loading.
    By cmrudd in forum Data
    Replies: 1
    Last Post: Oct 3rd, 2005, 03:58 AM
  4. Hibernate and lazy load
    By mfuller in forum Data
    Replies: 2
    Last Post: Apr 15th, 2005, 12:37 PM
  5. Spring, JSF, Hibernate & Lazy Collections
    By e.medina.m in forum Data
    Replies: 3
    Last Post: Mar 9th, 2005, 03:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •