JSF + Hibernate : HibernateException
Bonjour,
J'ai une appli basique avec un formulaire.
Je voudrais simplement insérer le prenom et le nom de la personne (qu'elle a saisit dans le formulaire) dans la BDD. (Sans passer par jsf, j'ai pu faire fonctionner hibernate avec un autre exemple)
Voici le récapitulatif après saisit du formulaire (cliquer sur confirmer pour insérer en base) - j'ai viré le superflux:
Code:
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
|
<h:form>
<h2>
Confirmation inscription
</h2>
<h4>
Confirmation d'inscription
</h4>
<table>
<tr>
<td>Prénom: </td>
<td>
<h:outputText value="#{UserBean.prenom}"/>
</td>
</tr>
<tr>
<td>Nom:</td>
<td>
<h:outputText value="#{UserBean.nom}"/>
</td>
</tr>
<tr>
<td>Sexe:</td>
<td>
<h:outputText value="#{UserBean.genre}"/>
</td>
</tr>
</table>
<p><h:commandButton value="Editer" action="revise"/>
<h:commandButton value="Confirmer" action="#{UserBean.ajoutUtilisateurConfirme}" /> |
voici la fonction appelée par le clique sur "confirmer" dans la classe UserBean:
Code:
1 2 3 4 5
| public void ajoutUtilisateurConfirme(){
System.out.println("Prenom =" + this.getPrenom());
System.out.println("Nom = " + this.getNom());
AjoutUser p = new AjoutUser(this);
} |
La fonction d'ajout de User:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| public AjoutUser(UserBean usr){
createUser(usr);
}
private static void createUser(UserBean usr) {
Transaction tx = null;
Session session = SessionFactoryUtil.getInstance().getCurrentSession();
try {
tx = session.beginTransaction();
session.save(usr);
tx.commit();
} catch (RuntimeException e) {
if (tx != null && tx.isActive()) {
try {
// Second try catch as the rollback could fail as well
tx.rollback();
} catch (HibernateException e1) {
System.out.println("Error rolling back transaction");
}
// throw again the first exception
throw e;
}
}
} |
Et voici mon facesconfig, mais il n'y a qu'un bean UserBean:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<managed-bean>
<managed-bean-name>UserBean</managed-bean-name>
<managed-bean-class>com.ben.jsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/main.jsp</from-view-id>
<navigation-case>
<from-outcome>register</from-outcome>
<to-view-id>/register.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/register.jsp</from-view-id>
<navigation-case>
<from-outcome>register</from-outcome>
<to-view-id>/confirm.jsp</to-view-id>
</navigation-case>
</navigation-rule> |
Merci d'avance...
Je me dis qu'il y a peut être un incompatibilité entre jsf et hibernate...
au moment ou il récupère la session?
J'espère que quelqu'un aura la réponse.
Merci davance.