Iterating over a java.util.Set inside <p:dataGrid>. causes, The class org.eclipse.persistence.indirection.IndirectSet doesn't have the property xxx

StackOverflow https://stackoverflow.com/questions/22541976

I have three tables in MySQL database.

  • category
  • sub_category
  • product

The relationship between these tables is intuitive - one-to-many in the order in which they appear.


I'm getting a List<SubCategory> from MySQL database in which there is a java.util.Set<Product> for each sub category as obvious.

I'm iterating over List<SubCategory> in <p:dataGrid> as follows.

<p:dataGrid id="dataGrid" rows="4" first="0" columns="1" value="#{productDetailsManagedBean}" var="row" rowIndexVar="rowIndex" paginator="true" paginatorAlwaysVisible="false" pageLinks="10" lazy="true" rowsPerPageTemplate="1,2,3">

        <h:panelGrid columns="1" style="width:100%">
            <h:outputText value="#{row.subCatId}"/>

            <p:carousel id="carousel" value="#{row.productSet}" var="prodRow" numVisible="4" headerText="#{row.subCatName}">
                <h:outputText value="#{prodRow.prodId}"/>
            </p:carousel>

        </h:panelGrid>

</p:dataGrid>

The value attribute of <p:carousel> doesn't function. It just says, {IndirectSet: not instantiated}. Hence, accessing any product using EL like #{prodRow.prodId} as seen with <h:outputText> will throw an exception like,

javax.el.PropertyNotFoundException: The class 'org.eclipse.persistence.indirection.IndirectSet' does not have the property 'prodId'

When I change,

<h:outputText value="#{prodRow.prodId}"/>

to

<h:outputText value="#{row.productSet.size()}"/>

It correctly shows the size of row.productSet (it is not empty, the size is exactly the same as the number of rows for each sub category in List<SubCategory>. The Set is precisely initialized).

Why does it throw an exception while accessing a property of Product like #{prodRow.prodId}?

How to solve this problem?

This is something explained precisely here but I couldn't solve the same problem in this particular situation.

I'm using JPA provided by EclipseLink 2.3.2

有帮助吗?

解决方案

I have tried changing java.util.Set to java.util.List but doing so requires too many changes to the application which is a pain.

Instead, I have turned java.util.Set into an array using its toArray() method and it worked.

<p:carousel id="carousel" value="#{row.productSet.toArray()}" var="prodRow" numVisible="6" headerText="#{row.subCatName}">
    <!--<h:outputText value="#{prodRow.prodId}"/>-->
    <p:graphicImage library="fileUpload" name="product_image/medium/#{prodRow.productImageSet.toArray()[0].prodImage}" alt="#{prodRow.prodName}" height="140" width="135"/>
</p:carousel>

I have replaced <h:outputText> with <p:graphicImage> for a concrete requirement for displaying images on <p:graphicImage>.

I don't know whether the problem has to do with the JPA provider EclipseLink itself or java.util.Set. If someone knows, please clarify.


EDIT:

I have now changed every inverse (or mapped by) field from java.util.Set to java.util.List everywhere in my application and it works just fine. There is no need to use .toArray() as have to be used with java.util.Set.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top