All posts tagged p:selectCheckboxMenu

  • Hibernate LazyInitializationException And p:selectCheckboxMenu

    I had a simple Entity with a @oneToMany relationship.

    Let’s call the Entity “Store” and the Entity of the relationship “Product”, obviously a Store has many Products.
    When it comes to use selectCheckboxMenu with the input (update) of products, a bug arise “org.hibernate.LazyInitializationException: could not initialize proxy – no Session”.
    For some reason using the primefaces selectCheckboxMenu (or h:selectmanycheckbox of the slandered JSF components) would end the Session of the current transaction.

    to solve this issue I had to supply the type of my collection to the component with attribute name=”collectionType”.

    <p:selectCheckboxMenu > 	 	 
     <f:attribute name="collectionType" value="java.util.ArrayList" />	 	 
     <f:selectItems value="#{bean.getStoreProducts()}" 	 	 
     var="product" itemLabel="#{product.name}"	 	 
     itemValue="#{product}" />	 	 
    </p:selectCheckboxMenu>

    it depends on your type of List if it’s a Set for example you can use java.util.HashSet instead of java.util.ArrayList.