Hibernate Criteria - 带有子集的resultTransformer

时间:2014-12-31 08:48:06

标签: java hibernate orm criteria


我在有多个孩子的桌子上遇到Hibernate Criteria问题。

这是我的标准:

crit = session.createCriteria(PrescRicette.class)
            .createAlias("prescEpisodi", "episodi", Criteria.LEFT_JOIN)
            .createAlias("prescEsenzioni", "prescEsenzioni", Criteria.LEFT_JOIN)
            .createAlias("prescRicetteAmb", "ricetteAmb", Criteria.LEFT_JOIN)
            .createAlias("prescRicetteFarma", "ricetteFarma", Criteria.LEFT_JOIN)
            .createAlias("prescRicettePrescrizioni", "ricettePrescrizioni", Criteria.LEFT_JOIN)
            .createAlias("prescIdentificativiRicette", "prescIdentificativiRicette", Criteria.LEFT_JOIN)
            .createAlias("episodi.prescAssistiti", "assistito", Criteria.LEFT_JOIN)
            .createAlias("ricetteAmb.prescFascePriorita", "fascePriorita", Criteria.LEFT_JOIN)
            .createAlias("ricetteFarma.prescNoteCuf", "noteCuf", Criteria.LEFT_JOIN)
            .createAlias("ricettePrescrizioni.prescPrescrizioni", "prescrizioni", Criteria.LEFT_JOIN)
            .createAlias("prescrizioni.prescPrestazioni", "prestazioni", Criteria.LEFT_JOIN)
            .createAlias("prestazioni.prescBranche", "branche", Criteria.LEFT_JOIN)
            .createAlias("prestazioni.prescPrestazioni030", "prestazioni030", Criteria.LEFT_JOIN)
            .createAlias("prescrizioni.prescFarmaci", "farmaci", Criteria.LEFT_JOIN)
            .createAlias("farmaci.prescFarmaGruppiEquiv", "farmaciGruppiEquiv", Criteria.LEFT_JOIN)
            .createAlias("farmaci.prescFarmaci030", "farmaci030", Criteria.LEFT_JOIN)
            .createAlias("farmaciGruppiEquiv.prescGruppiEquivalenza", "gruppiEquiv", Criteria.LEFT_JOIN)
            .createAlias("prescEsenzioni.prescTipiEsenzioni", "prescTipiEsenzioni", Criteria.LEFT_JOIN)
            .add(Restrictions.eq("assistito.idPazAnaPaz", idPaz))
            .add(Restrictions.isNotEmpty("prescIdentificativiRicette"))
            .addOrder(Order.desc("dataEmissione"))
            .setResultTransformer(new AliasToBeanResultTransformer(PrescRicette.class));

    ricetteDB = crit.list();

我之所以这样做是因为出于性能原因,我需要以非惰性模式获取数据,并在表之间进行LEFT JOIN。

这是错误:


Could not find setter for prescTipiEsenzioni on class org.oshc.hibernate.modules.gestioneRicette.PrescRicette
org.hibernate.PropertyNotFoundException: Could not find setter for prescTipiEsenzioni on class org.oshc.hibernate.modules.gestioneRicette.PrescRicette
    at org.hibernate.property.ChainedPropertyAccessor.getSetter(ChainedPropertyAccessor.java:68)
    at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:87)
    at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow(CriteriaLoader.java:139)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:629)
    at org.hibernate.loader.Loader.doQuery(Loader.java:724)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.doList(Loader.java:2228)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
    at org.hibernate.loader.Loader.list(Loader.java:2120)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
    at org.oshc.bf.modules.gestioneRicette.command.RicettePersistenceManager.recuperaRicettePaziente(RicettePersistenceManager.java:170)
    at org.oshc.bf.modules.gestioneRicette.services.RecuperoRicetteService.eseguiCommandRecuperaRicettePaziente(RecuperoRicetteService.java:97)
    at org.oshc.bf.modules.gestioneRicette.services.RecuperoRicetteService.recuperaRicettePerPaziente(RecuperoRicetteService.java:62)
    at org.oshc.pf.modules.gestioneRicette.dwr.GestioneRicetteDAO.getRicettePerStoricoPrescrizioni(GestioneRicetteDAO.java:269)
    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.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
    at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
    at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
    at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
    at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.oshc.pf.util.LogFilter.doFilter(LogFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:619)
[WARN] DefaultRemoter - Method execution failed:  org.hibernate.PropertyNotFoundException: Could not find setter for prescTipiEsenzioni on class org.oshc.hibernate.modules.gestioneRicette.PrescRicette
    at org.hibernate.property.ChainedPropertyAccessor.getSetter(ChainedPropertyAccessor.java:68)
    at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:87)
    at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow(CriteriaLoader.java:139)
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:629)
    at org.hibernate.loader.Loader.doQuery(Loader.java:724)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    at org.hibernate.loader.Loader.doList(Loader.java:2228)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
    at org.hibernate.loader.Loader.list(Loader.java:2120)
    at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1596)
    at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
    at org.oshc.bf.modules.gestioneRicette.command.RicettePersistenceManager.recuperaRicettePaziente(RicettePersistenceManager.java:170)
    at org.oshc.bf.modules.gestioneRicette.services.RecuperoRicetteService.eseguiCommandRecuperaRicettePaziente(RecuperoRicetteService.java:97)
    at org.oshc.bf.modules.gestioneRicette.services.RecuperoRicetteService.recuperaRicettePerPaziente(RecuperoRicetteService.java:62)
    at org.oshc.pf.modules.gestioneRicette.dwr.GestioneRicetteDAO.getRicettePerStoricoPrescrizioni(GestioneRicetteDAO.java:269)
    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.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
    at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
    at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
    at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
    at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
    at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.oshc.pf.util.LogFilter.doFilter(LogFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Thread.java:619)

[WARN] BaseCallMarshaller - --Erroring: batchId[25] message[org.hibernate.PropertyNotFoundException: Could not find setter for prescTipiEsenzioni on class org.oshc.hibernate.modules.gestioneRicette.PrescRicette]

现在,问题是我不希望在PrescRicette上设置实体prescTipiRicette,而且我无法在标准上找到错误。

如果没有resultTransformer字段映射就好了,但是为每个子节点复制了根实体。 使用.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY),根元素不会被复制,但每个根只有一个子元素。

这个实体太多了,无法复制和粘贴在这个问题中,所以在一些更多的片段中只需要问一下,我会添加它们。

提前致谢, 马蒂亚

1 个答案:

答案 0 :(得分:0)

代码:

createAlias("prescEsenzioni.prescTipiEsenzioni", "prescTipiEsenzioni", Criteria.LEFT_JOIN)

例外:

org.hibernate.PropertyNotFoundException: Could not find setter for prescTipiEsenzioni on class org.oshc.hibernate.modules.gestioneRicette.PrescRicette

AliasToBeanResultTransformer正在尝试将地图prescTipiEsenzioni转换为您的类org.oshc.hibernate.modules.gestioneRicette.PrescRicette但在此过程中失败,因为它缺少prescTipiEsenzioni的setter。

您是否可以检查PrescRicette是否具有prescTipiEsenzioni属性和相应的字段/设置者?