i'm currently working on cutting out wrapper classes in one area of our application, and using the entity directly instead of a wrapper class, and i came across a weird error when i tried iterating a Set in the entity:
javax.el.PropertyNotFoundException: listTADs.xhtml value="#{del.name}": Property 'name' not found on type org.hibernate.collection.PersistentSet
here's some of the code.
##########
TAD.java:
@Entity
@Table(name = "TAD")
...
public class TAD extends Persistent implements Serializable {
...
/** The despatch party*/
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name="ADP",
joinColumns={@JoinColumn(name="AGREEMENT_ID")},
inverseJoinColumns={@JoinColumn(name="PARTY_ID")})
private Set<TAP> despatchParties = new HashSet<TAP>();
...
public Set<TAP> getDespatchParties() {
return despatchParties;
}
...
TAP.java:
@Entity
@Table(name = "TAP")
...
public class TAP extends Persistent implements Serializable {
...
/** The name */
@Column(name = "NAME")
@Basic(fetch = FetchType.EAGER)
private String name;
...
public String getName() {
return name;
}
listTADs.xhtml:
<rich:dataTable id="pickupParties" value="#{tad.despatchParties}" var="del">
<rich:column>
<f:facet name="header">
<h:outputText
value="#{msg['label.db.PARTY_NAME']}" />
</f:facet>
<h:outputText value="#{del.name}"></h:outputText>
</rich:column>
...
##########
what was happening was that
despatchParties.size() was always 1 no matter how many entries it had, e.g. 3
TAPs, and
the del var was the container for the actual set, so the application was trying to call
getName() on the whole Set--which obviously wouldn't work because
java.util.Set doesn't have a
getName() method. it looked like this:
Method not found: [TAP [id=2745,
agreementOwnerId=TestBuyer, name=XHentested_1469,
idInAgreement=XHID_1469, eanLocationNumber=null, ldapId=null, city=Oslo,
postCode=0152, street=Prinsens gt. 1, role=Despatch Party,
parentOrganizationId=null, goodstype=null, countryCode=NO,
contact=example@example.no, language=no_NO, langRole=null,
selected=false, referredPartyId=null]].getName()
so to iterate the Set in the
rich:dataTable i had to
add a toArray() call so that del var would be an entry in the actual set:
<rich:dataTable id="pickupParties" value="#{tad.despatchParties.toArray()}" var="del">
<rich:column>
<f:facet name="header">
<h:outputText
value="#{msg['label.db.PARTY_NAME']}" />
</f:facet>
<h:outputText value="#{del.name}"></h:outputText>
</rich:column>
...