I have a class Evenement and a class Utilisateur which are mapping into a Evenement's Mysql table and a Utilisateur's Mysql table as following :
<class name="com.cfort.calendrier.Evenement" table="evenement">
<id name="id" column="id">
<generator class="hilo"/>
</id>
<property name="moment" type="string" length="12"/>
<property name="debut" type="string" length="10"/>
<property name="fin" type="string" length="10"/>
<property name="titre" type="string" length="40"/>
<property name="description" type="string" length="200"/>
</class>
<class name="com.cfort.utilisateur.Utilisateur" table="utilisateur" >
<id name="identifiant" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<property name="dateAbonnement" type="date"/>
<property name="datePaiement" type="date"/>
<property name="modeReglement">
<column name="modeReglement" sql-type="varchar(30)"/>
</property>
<property name="nbPoints" type="integer"/>
<set name="evenements">
<key column="utilisateur_numero"/>
<one-to-many class="com.cfort.calendrier.Evenement"/>
</set>
</class>
When i insert a evenement with the code as below :
Code:
public void insererEvenement(Evenement evt) {
try
{
Session session = HibernateDAOFactory.creerConnection();
Transaction tx = session.beginTransaction();
session.save(evt);
tx.commit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
i have the error :
java.sql.SQLException : can't call commit when autocommit=true
...
Can you explain to me what wrong because this kind of code works well
for others objects?
You will find here the content of the hibernate.cfg.xml file :
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<!-- properties -->
<property name="connection.datasource">java:comp/env/jdbc/portail</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<!-- mapping files -->
<mapping resource="utilisateur.hbm.xml"/>
</session-factory>
</hibernate-configuration>