Menu

Condition on a DescriptionList in an Embeddable Class

Tim Gaul
2015-04-28
2015-11-02
  • Tim Gaul

    Tim Gaul - 2015-04-28

    Hi

    I have an embeddable class with a description list that I'm trying to filter based on a collection:

    public class OrderLineDetail {
    @ManyToOne(fetch=FetchType.LAZY)
    @DescriptionsList(
    order="${sortSeq} desc",
    depends="this.sizes",
    condition="IN (${sizes})"
    )
    @JoinColumn(name = "SIZE_ID", nullable = false)
    private Size size;

    // Just to get the sizes filter
    public Collection<Size> getSizes() {
    
        return sizes;
    
    }
    

    }

    However I'm receiving the following error:

    Apr 28, 2015 6:37:41 PM org.apache.catalina.core.ApplicationDispatcher invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    org.openxava.util.ElementNotFoundException: Subview orderLineDetail not found in view of Order. Try to use this.orderLineDetail
    at org.openxava.view.View.getSubview(View.java:782)
    at org.openxava.view.View.getValue(View.java:716)
    at org.openxava.view.View.getValue(View.java:753)
    at org.apache.jsp.xava.editors.descriptionsEditor_jsp._jspService(descriptionsEditor_jsp.java:223)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jsp.xava.reference_jsp._jspService(reference_jsp.java:470)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:652)
    at org.openxava.web.taglib.DescriptionsListTag.doStartTag(DescriptionsListTag.java:47)
    at org.apache.jsp.xava.editors.elementCollectionEditor_jsp._jspService(elementCollectionEditor_jsp.java:453)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jsp.xava.collection_jsp._jspService(collection_jsp.java:129)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
    at org.openxava.web.layout.AbstractJspPainter.includeJspPage(AbstractJspPainter.java:82)
    at org.openxava.web.layout.impl.DefaultLayoutPainter.beginCollection(DefaultLayoutPainter.java:964)
    at org.openxava.web.layout.impl.DefaultLayoutCollectionBeginElement.render(DefaultLayoutCollectionBeginElement.java:34)
    at org.openxava.web.layout.LayoutPainterManager.renderElements(LayoutPainterManager.java:82)
    at org.openxava.web.layout.LayoutPainterManager.renderView(LayoutPainterManager.java:41)
    at org.apache.jsp.xava.detail_jsp._jspService(detail_jsp.java:165)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jsp.xava.core_jsp._jspService(core_jsp.java:301)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    at org.openxava.web.servlets.Servlets.getURIAsString(Servlets.java:120)
    at org.openxava.web.servlets.Servlets.getURIAsString(Servlets.java:99)
    at org.openxava.web.dwr.Module.getURIAsString(Module.java:211)
    at org.openxava.web.dwr.Module.fillResult(Module.java:222)
    at org.openxava.web.dwr.Module.request(Module.java:97)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    Any ideas what I'm doing wrong?

    Thanks!

     
  • Javier Paniza

    Javier Paniza - 2015-04-30

    Hi Tim:

    depends="this.sizes", // Not supported
    condition="IN (${sizes})" // Here you should use ? instead of ${sizes}
    

    That is not supported. You cannot depend on a collection and send the collection as a whole as argument for IN. You have to rewrite it sending an atomic value and using a where in the condition, something like this:

    condition="IN (select s.code from Size s where s.parent = ?)"
    

    Help others in this forum as I help you.

     
    • Tim Gaul

      Tim Gaul - 2015-05-20

      Thanks Javier,

      I've only gone back to addressing this now and will try your suggestions.

       
  • Tim Gaul

    Tim Gaul - 2015-05-20

    Thanks Javier,

    I've only gone back to addressing this now and will try your suggestions.

     
  • Tim Gaul

    Tim Gaul - 2015-07-14

    Hi Javier

    What I'm trying to do is to limit the size options on the basis of what department the order line detail is in, this is mapped on a table/class called DepartmentSize. I've tried, but am receiving a "Editor not available":

    @Embeddable
    public class OrderLineDetail {
    @ManyToOne(fetch=FetchType.LAZY)
    @DescriptionsList(
    order="${sortSeq} desc",
    depends="orderLine.product.department",
    condition="IN (SELECT ds.size FROM DepartmentSize ds WHERE ds.department = ?)"
    )
    @JoinColumn(name = "SIZE_ID", nullable = false)
    private Size size;

    @Parent
    private OrderLine orderLine;
    

    Any help would be appreciated.

    Regards

    Tim

     
  • Javier Paniza

    Javier Paniza - 2015-07-16

    Hi Tim,

    Put here the stacktrace and the complete code of OrderLine and OrderLineDetail.


    Help others in this forum as I help you.

     
    • Tim Gaul

      Tim Gaul - 2015-10-06
      Post awaiting moderation.
    • Tim Gaul

      Tim Gaul - 2015-10-06
      Post awaiting moderation.
    • Tim Gaul

      Tim Gaul - 2015-10-06

      Hi Javier

      My posts in reply to your request don't seem to be appearing on the thread! Please let me know if you haven't received them.

      Thanks

       
    • Tim Gaul

      Tim Gaul - 2015-10-06
      Post awaiting moderation.
    • Tim Gaul

      Tim Gaul - 2015-10-06

      Hi Javier

      I've simplified (for testing) to this:

      @DescriptionsList(
              order="${sortSeq} desc",        
              condition="${id} IN (SELECT size.id FROM ${DepartmentSize})"
      )
      

      OR

      @DescriptionsList(
              order="${sortSeq} desc",        
              condition="e.id IN (SELECT ds.size.id FROM DepartmentSize ds)"  
      )   
      

      And am receiving:

      Caused by: org.openxava.util.ElementNotFoundException: Subview orderLineDetails not found in view of Order. Try to use this.orderLineDetails

      Log attached.

      Thanks for the help!

      Tim

       
  • Javier Paniza

    Javier Paniza - 2015-10-08

    Hi Tim,

    The problem is "DepartmentSize is not mapped".

    Have you defined DepartmentSize as an @Entity?
    If you go to http://localhost:8080/YourApp/m/DepartmentSize does it work?

    Please, put here the source code for DepartmentSize.


    Help others in this forum as I help you.

     
    • Tim Gaul

      Tim Gaul - 2015-10-08

      Thanks Javier.

      After some investigation I've worked out that DepartmentSize is an @Embeddable, embedded in Department. Would this cause the mapping to fail. If so, what can I do?

      package za.co.exafricanus.retail.model;
      
      import javax.persistence.*;
      import javax.persistence.Table;
      
      import org.hibernate.annotations.*;
      import org.openxava.annotations.*;
      
      import za.co.exafricanus.retail.actions.*;
      
      @Embeddable
      @Table(name="RET_DEPARTMENT_SIZE",
          uniqueConstraints={
              @UniqueConstraint(name="DEPARTMENT_SIZE_UK1", columnNames={"DEPARTMENT_ID", "SIZE_ID"})
      })
      public class DepartmentSize {
      
          @Column(name = "SORT_SEQ", precision = 4, nullable = false)
          private int sortSeq;
      
          @Column(name = "SIZE_DESCRIPTION", length = 100, nullable = false)
          private String sizeDescription;  
      
          @ManyToOne(fetch=FetchType.LAZY) 
          @DescriptionsList
          @JoinColumn(name = "SIZE_ID", nullable = false)
          private Size size;  
      
          @Parent 
          private Department department;   
      
          public void setSortSeq(int aValue) {
              sortSeq = aValue;
          }
      
          public int getSortSeq() {
              return sortSeq;
          }
      
          public Size getSize() {
              return size;
          }
      
          public void setSize(Size size) {
              this.size = size;
          }
      
          public String getSizeDescription() {
              return sizeDescription;
          }
      
          public void setSizeDescription(String sizeDescription) {
              this.sizeDescription = sizeDescription;
          }
      
          public Department getDepartment() {
              return department;
          }
      
          public void setDepartment(Department department) {
              this.department = department;
          }
      }
      

      Tim

       

      Last edit: Tim Gaul 2015-10-08
  • Javier Paniza

    Javier Paniza - 2015-10-12

    Hi Tim,

    If the RET_DEPARTMENT_SIZE has a primary key, and I think that that is the case because you use @UniqueConstraint, you can map that map with an entity and use that entity in your query.

    That is, create a class like this:

    @Embeddable
    @Table(name="RET_DEPARTMENT_SIZE")
    ...
    public class RetDepartmentSize {
    
        ...
    }
    

    And in your condition write:

    @DescriptionsList(
        order="${sortSeq} desc",        
        condition="${id} IN (SELECT size.id FROM ${RefDepartmentSize})"
    )
    

    Help others in this forum as I help you.

     
    • Tim Gaul

      Tim Gaul - 2015-10-19

      Hi Javier

      As it's Embeddable I haven't added a primary key. How would I do that, though I do have a unique key that could be used.

      Regards

      Tim

       
  • Javier Paniza

    Javier Paniza - 2015-10-21

    Hi Tim:

    though I do have a unique key that could be used.

    So map that column to the primary key of the entity.


    Help others in this forum as I help you.

     
    • Tim Gaul

      Tim Gaul - 2015-10-29

      Javier,

      @ElementCollection cannot take a primary key, because an @Embeddable types cannot have an identifier. You've told me to map that column to the primary key of the entity, please could you explain where this would be done?

      Thanks!

      Tim

       
  • Javier Paniza

    Javier Paniza - 2015-11-02

    Hi Tim:

    please could you explain where this would be done?

    You said me that you have a unique key, than you can use it. If not you could find for a combination of field that would be unique and use them as primeray key, even if you have to use all fields. That last option would be add a autogenerated primary key to the table.


    Help others in this forum as I help you.

     

Log in to post a comment.