En developpement web tout fonctionne sauf en client riche avec swing4
voici le code dans swing:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
Object source = arg0.getSource();
		if (source==jButton0) {
 
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		User user = new User();
		user.setLoginUser(jTextField0.toString());
		user.setPasswordUser(jTextField1.toString());
		session.save(user);
 
		session.getTransaction().commit();
		HibernateUtil.getSessionFactory().close();
hibernate uti
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
package Util;
 
import org.hibernate.*;
import org.hibernate.cfg.*;
 
 
public class HibernateUtil {
private static final SessionFactory sessionFactory;
	static {
		try { sessionFactory = new Configuration().configure().buildSessionFactory();
		} catch (Throwable ex) {System.err.println("Echec operation SessionFactory" + ex);
		throw new ExceptionInInitializerError(ex);
		}
	}
 
	public static SessionFactory getSessionFactory() {
		return sessionFactory;}
	}


hibernate config
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">L099339R</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mabasse</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
		<property name="current_session_context_class">thread</property>
		<property name="hibernate.show_sql">true</property>
        <mapping resource="Entite/User.hbm.xml" />
        <mapping resource="Entite/Course.hbm.xml" />
        <mapping resource="Entite/Entite2.hbm.xml" />
        <mapping resource="Entite/Applabsuser.hbm.xml" />
    </session-factory>
</hibernate-configuration>
la classe persistante
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
package Entite;
 
// default package
// Generated 8 juil. 2010 12:46:15 by Hibernate Tools 3.2.4.GA
 
/**
 * User generated by hbm2java
 */
public class User implements java.io.Serializable {
 
	private Integer idUser;
	private String loginUser;
	private String passwordUser;
 
	public User() {
	}
 
	public User(String loginUser, String passwordUser) {
		this.loginUser = loginUser;
		this.passwordUser = passwordUser;
	}
 
	public Integer getIdUser() {
		return this.idUser;
	}
 
	public void setIdUser(Integer idUser) {
		this.idUser = idUser;
	}
 
	public String getLoginUser() {
		return this.loginUser;
	}
 
	public void setLoginUser(String loginUser) {
		this.loginUser = loginUser;
	}
 
	public String getPasswordUser() {
		return this.passwordUser;
	}
 
	public void setPasswordUser(String passwordUser) {
		this.passwordUser = passwordUser;
	}
 
}
User.hbm.xml
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
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 8 juil. 2010 12:46:16 by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
    <class name="Entite.User" table="user" catalog="mabasse">
        <id name="idUser" type="java.lang.Integer">
            <column name="id_user" />
            <generator class="identity" />
        </id>
        <property name="loginUser" type="string">
            <column name="login_user" length="25" not-null="true" />
        </property>
        <property name="passwordUser" type="string">
            <column name="password_user" length="25" not-null="true" />
        </property>
    </class>
</hibernate-mapping>
voici ceux qu'il y a sur la cosole
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
GRAVE: Data truncation: Data too long for column 'login_user' at row 1
Exception in thread "AWT-EventQueue-0" org.hibernate.exception.DataException: could not insert: [Entite.User]
Merci pour toute l'aide que vous pourrez me donner