0

嗨,我有这样的 hbm

<hibernate-mapping package="com.mydomain.demand" default-access="field">
  <class name="DemandHistory" table="DMND_PROFL_HIST">
    <id name="id" column="DMND_PROFL_HIST_ID" type="long">
      <generator class="sequence">
        <param name="sequence">DMND_PROFL_HIST_ID_SEQ</param>
      </generator>
    </id>
    <version name="version" column="WRITE_COUNT" type="long" unsaved-value="null" />
    ................
            ...............
    <property name="demandHistSyncId" column="DMND_PROFL_HIST_SYNC_ID" type="long" />
    <many-to-one name="demandStatType" column="DMND_PROFL_STAT_TYP_ID" class="com.mydomain.types.DemandProfileStatusType"
      insert="false" update="false" />
    <bag name="demandHistLineItems" **fetch="select"**>
      <key property-ref="demandHistSyncId" column="DMND_PROFL_HIST_SYNC_ID" />
      <one-to-many class="com.mydomain.demand.DemandLineItemHistory" />
    </bag>
    <property name="demandId" column="DMND_PROFL_ID" type="long" />
    <property name="clmRcvblId" column="CLM_RECVBL_ID" type="long" />
    <property name="renterResponsible" column="RENTR_RSPBL_IND" type="boolean" />
    <property name="billerNoticeSent" column="BILLER_NOTC_SNT_IND" type="boolean" />
    <property name="subroPartyId" column="SUBRO_PRTY_ID" type="long" />
    <property name="demandCreateAdjusterId" column="DMND_PROFL_CRTE_ADJR_ID" type="string" />
    <property name="demandCreateDt" column="DMND_PROFL_CRTE_DTE" type="calendar" />
  </class>
</hibernate-mapping>

它抛出

LazyInitializationException:延迟初始化角色集合失败

例外。如果我将获取更改为“加入”它可以工作,但没有获得所需的记录。不了解确切的问题。请指教

堆栈跟踪是

2013-03-15 11:40:32,878|WARN|dev|||http-8081-1|com.myapp.webservice.demand.DemandHistoryWebServiceImpl|DH_WEBSERV_FAILED
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.mydomain.demand.DemandHistory.demandHistLineItems, no session or session was closed
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:380)
    at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:372)
    at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:119)
    at org.hibernate.collection.PersistentBag.isEmpty(PersistentBag.java:255)
    at org.apache.commons.collections.CollectionUtils.isEmpty(CollectionUtils.java:979)
    at org.apache.commons.collections.CollectionUtils.isNotEmpty(CollectionUtils.java:992)
    at com.myapp.service.demand.DemandHistorySearchResults.toResultItems(DemandHistorySearchResults.java:65)
    at com.myapp.service.demand.DemandHistorySearchResults.<init>(DemandHistorySearchResults.java:39)
    at com.myapp.domain.demand.DemandHistoryDao.search(DemandHistoryDao.java:93)
    at com.myapp.service.demand.DemandHistoryServiceImpl.searchDemandHistory(DemandHistoryServiceImpl.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy12.searchDemandHistory(Unknown Source)
    at com.myapp.webservice.demand.DemandHistoryWebServiceImpl.getDemandHistory(DemandHistoryWebServiceImpl.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.myappserver.ws.RequestHandler.invokeEndpoint(RequestHandler.java:459)
    at com.myapp.server.ws.RequestHandler.service(RequestHandler.java:260)
    at com.myapp.server.ws.RsiEndpointServlet.doPost(RsiEndpointServlet.java:91)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

以及 DemandHistorySearchResults 中的代码:

public class DemandHistorySearchResults
    extends PageableSearchResults<DemandHistorySearchResultItem> {
  public DemandHistorySearchResults(List<DemandHistory> profiles, PaginationDetail pageDetail) {
    // set pagedetails
    setPaginationDetail(pageDetail);

    List<DemandHistorySearchResultItem> items = toResultItems(profiles);
    setPagableData(items);
    setSearchPerformed(true);
  }

  private List<DemandHistorySearchResultItem> toResultItems(List<DemandHistory> profiles) {
    List<DemandHistorySearchResultItem> items = CollectionFactory.newArrayList();

    if (CollectionUtils.isEmpty(profiles)) {
      return items;
    }

    for (int i = 0; i < profiles.size(); i++) {
      DemandHistory profile = profiles.get(i);
      DemandHistorySearchResultItem item = new DemandHistorySearchResultItem();
      item.setDemandHistId(profile.getId());
      item.setDemandId(profile.getDemandId());
      item.setDemandCreateAdjusterId(profile.getDemandCreateAdjusterId());
      item.setDemandCreateDt(profile.getDemandCreateDt());

      if (profile.getDemandStatType() != null) {
        item.setDemandStatTypeDesc(profile.getDemandStatType().getDescription());
      }

      ***List<DemandLineItemHistory> lineItems = profile.getDemandHistLineItems();***

      if (CollectionUtils.isNotEmpty(lineItems)) {
        List<DemandLineHistoryResultItem> resultItems = CollectionFactory.newArrayList();

        for (DemandLineItemHistory lineItem : lineItems) {
          DemandLineHistoryResultItem resultItem = new DemandLineHistoryResultItem();

          CostType costType = lineItem.getCostType();

          if (costType != null) {
            resultItem.setCostTypeId(costType.getId());
            resultItem.setCostTypeCode(costType.getCode());

            // Rule - If cost type is Misc Charge then cost description would be Line Item Misc Charge Descriprion
            if (costType.isMiscCharge()) {
              resultItem.setCostTypeDesc(lineItem.getMiscChargDsc());
            }
            else {
              resultItem.setCostTypeDesc(costType.getDescription());
            }
          }

          resultItem.setLineItemAmt(lineItem.getLineItemAmt());
          resultItem.setLineItemAmtDelta(lineItem.getLineItemAmtDelta());

          resultItems.add(resultItem);
        }

        item.setDemandHistLineItems(resultItems);
      }

      item.setBillerNoticeSent(profile.getBillerNoticeSent());
      item.setClmRcvblId(profile.getClmRcvblId());
      item.setRenterResponsible(profile.getRenterResponsible());
      item.setSubroPartyId(profile.getSubroPartyId());
      item.setRowNumber(i + getPaginationDetail().getRecordStart());
      item.setTotalCount(getPaginationDetail().getTotalRecords());

      items.add(item);
    }

    return items;
  }
4

0 回答 0