I have a many-to-many relationship between the two entities called events and artists, both are annotated to be lazy loaded. When I load an artist, I initialize its events because the session will be closed afterwards using
Hibernate.initialize(artist.getEvents());
A test in pure Java works fine and I can access the events and its properties afterwards.
But in the .xhtml page presenting the result, I can only access the artist's properties and test if there are any events available, Artist is the backing bean, getData() returns the Artist, the following line still works:
<h:outputText value="No events available" rendered="#{empty artist.data.events}"/>
But when I want to access the properties of the events in a dataTable using
<h:dataTable value="#{artist.data.events}" var="event" rendered="#{not empty artist.data.events}">
<h:column>
<h:outputText value="#{event.title}"/>
</h:column>
</h:dataTable>
I get the followig exception:
/artist.xhtml @48,63 value="#{event.title}": The class 'org.hibernate.collection.PersistentSet' does not have the property 'title'.
My first thought was that Hibernate's initialize method does not work together with JSF2, but event when I change the FetchType from LAZY to EAGER I end up getting the same result.
The Event class looks like this, for brevity I only included the parts relevant to the title property:
@Entity()
@Table(name="Events")
@SequenceGenerator(name="events_id", sequenceName="event_seq", initialValue=1, allocationSize=1)
public class EventData implements Serializable {
private String title;
// other private variables
public EventData() {}
public EventData(String title, ...) {
this.title = title;
// ...
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
// other setters/getters, equals/getHashCode overrides
}