Bonjour,
J'ai une table livre et je veux effectué la recherche par titre mais ça fonctionne pas.
LivreBean.java
1 2 3 4 5 6 7 8
| public Livre getLivreByTitle()
{
return lDao.getByTitle(motCle);
}
public void SetLivreByTitle(String title)
{
this.motCle=title;
} |
LivreDao.java
1 2 3 4 5 6 7
| public Livre getByTitle(String titre)
{
Query query = em.createQuery("SELECT t FROM Livre t where t.titre= :title");
query.setParameter("title","titre");
Livre result = (Livre) query.getSingleResult();
return result;
} |
recherche.xhtml
1 2 3 4 5 6
| <h:panelGrid columns="3">
<h:outputLabel value="Search: "/>
<h:inputText id="keyword" value="#{livreBean.motCle}" required="true" label="Keyword" />
<h:commandButton value="Ajouter" action="Emprunt.xhtml"/>
</h:panelGrid> |
affichage
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| <h:dataTable value="#{livreBean.livreByTitle}" var="l" border="2" rowClasses="row1,row2">
<h:column>
<f:facet name="header">
<h:outputText value="ID"/>
</f:facet>
<h:outputText value="#{l.idElement}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="nom"/>
</f:facet>
<h:outputText value="#{l.isbn}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="prenom"/>
</f:facet>
<h:outputText value="#{l.titre}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="adresse"/>
</f:facet>
<h:outputText value="#{l.categorie}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="telephone"/>
</f:facet>
<h:outputText value="#{l.etat}"/>
</h:column>
</h:dataTable> |
l'erreur:
Caused by: javax.persistence.NoResultException: getSingleResult() did not retrieve any entities.
Mais je sais pas pourquoi le mot clé n'arrive pas à la requête. Merci de m'aider, je n'arrive pas à résoudre ça.
Partager