Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

jsf - javax.el.PropertyNotFoundException: Property not found on type org.hibernate.collection.internal.PersistentSet

I try to recuperate data from association ManyToMany but i can't, this is my code.

Entity Produit :

@Entity
public class Produit implements Serializable {

@Id
@Column(name="Produit_ID")
@GeneratedValue
private Long id;
private String dq;
private String icForme;
private String ich;
private String icht;

@ManyToMany(cascade = {CascadeType.ALL})
 @JoinTable(name="produit_terminal", 
                joinColumns={@JoinColumn(name="Produit_ID")}, 
                inverseJoinColumns={@JoinColumn(name="Terminal_ID")})
    private Set<Terminal> terminals = new HashSet<Terminal>();

//getter setter

Entity Terminal :

@Entity
public class Terminal implements Serializable{

@Id
@GeneratedValue
@Column(name="Terminal_ID")
private Long id;
private String crimpkontakt;
private String equipment;
private String geometrie;
private String dcbt;
private String icb;
private String ak;

@ManyToMany(mappedBy="terminals")
private Set<Produit> produit = new HashSet<Produit>();

//getter setter

Class : ModuleJPADao

public List<Produit> parProduit(String cat){
    cat = "%" + cat + "%";
    Query query = getEntityManger().createQuery( "from "+ getPersistentClass().getSimpleName()
            +" u where u.produit LIKE :cat").setParameter( "cat", cat );
    List<Produit> module = (List) query.getResultList();
    return module;

}

Class : ModuleService

public List<Produit> tousModuleProduit(String produit) {

    if(produit!= null){
        return moduleDao.parProduit(produit);
    }
    else{
        return null;
    }
}

main-flow.xml

<view-state id="accueil" view="accueil.xhtml">
    <on-render>
        <evaluate expression="moduleService.tousModuleProduit(module.getProduit())"
            result="viewScope.recherche" />

    </on-render>
</view-state>

file.xhtml

 <p:accordionPanel value="#{recherche}" var="car">

                    <p:tab title="IcForme : #{car.icForme}">

                        <h:panelGrid columns="4" cellspacing="20">

                            <p:outputLabel value="ICHT: " />
                            <p:inputText value="#{car.icht}" />

                            <p:outputLabel value="terminals : " />
                            <h:form>
                                <h:dataTable value="#{car.terminals}" var="der" >
                                    <p:column>
                                        <h:outputText value="#{der.geometrie}" />
                                    </p:column>

                                </h:dataTable>
                            </h:form>


                        </h:panelGrid>
        ....

i can't get the value of geometrie; i got this erreur:

javax.el.PropertyNotFoundException: /WEB-INF/flows/main/accueil.xhtml @84,53 value="#{der.geometrie}": Property 'geometrie' not found on type org.hibernate.collection.internal.PersistentSet
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<h:dataTable value="#{car.terminals}" var="der">
    <p:column>
        <h:outputText value="#{der.geometrie}" />

javax.el.PropertyNotFoundException: Property 'geometrie' not found on type org.hibernate.collection.internal.PersistentSet

Thus, the #{car.terminals} is a Set<E>. The <h:dataTable>, <p:dataTable> and <ui:repeat> components doesn't support iterating over a Set<E>. The #{der} will then basically represent the Set<E> itself. The builtin support for iterating over Set<E> will come in future JSF 2.3 version.

If it's not an option to replace Set<E> by a List<E>, then just get an array out of it as below:

<h:dataTable value="#{car.terminals.toArray()}" var="terminal">

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...