Bonjour,

alors voila j'ai un projet dans lequel j'utilise JSF avec Hibernate.
J'ai mis un évènement sur un bouton d'une page pour qu'il exécute ma fonction insert (voir plus bas) mais cela n'ajoute rien dans la base. Je ne comprends vraiment pas...
Je n'ai pas d'erreur. J'utilise une BDD MySQL. J'ai les librairies qu'il faut.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
public void insertChecker() {
 
        try {
            Session session =
                    HibernateUtil.getSessionFactory().getCurrentSession();
            Transaction tx = session.beginTransaction();
            Checker newChecker = new Checker();
 
            newChecker.setLogin("test");
            newChecker.setPassword("test");
            //newChecker.setBooks(null);
 
            session.save(newChecker);
 
            tx.commit();
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
Et mon POJO Checker (pour info) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 
package bdd.objects;
// Generated 22 juin 2009 16:47:56 by Hibernate Tools 3.2.1.GA
 
 
import java.util.HashSet;
import java.util.Set;
 
/**
 * Checker generated by hbm2java
 */
public class Checker  implements java.io.Serializable {
 
 
     private Integer idChecker;
     private String login;
     private String password;
     private Set books = new HashSet(0);
 
    public Checker() {
    }
 
    public Checker(String login, String password, Set books) {
       this.login = login;
       this.password = password;
       this.books = books;
    }
 
 
 
    public Integer getIdChecker() {
        return this.idChecker;
    }
 
    public void setIdChecker(Integer idChecker) {
        this.idChecker = idChecker;
    }
    public String getLogin() {
        return this.login;
    }
 
    public void setLogin(String login) {
        this.login = login;
    }
    public String getPassword() {
        return this.password;
    }
 
    public void setPassword(String password) {
        this.password = password;
    }
    public Set getBooks() {
        return this.books;
    }
 
    public void setBooks(Set books) {
        this.books = books;
    }
 
}