I can save , update but not delete in the database.
Thanks for the help
Daniel Cloutier
Hibernate version 3.0 rc 1 with HSQLDB 1.7.3
-----------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="manus.dictionnaire.data.ImageImpl" table="IMAGES" >
<id name="id" type="int" column="IMAGE_ID" unsaved-value="null">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<property name="nomImage" type="string" length="50" not-null="true" unique="true" >
<meta attribute="field-description">Le nom propre, unique de cette image</meta>
<meta attribute="use-in-tostring">true</meta>
<!-- il faut repeter not-null="true" unique="true" dans column si on ajoute index-->
<column name="NOM_IMAGE" not-null="true" unique="true" index="INDEX_IMAGE"/>
</property>
<property name="hauteur" type="string" length="5" >
<meta attribute="field-description">La hauteur de l'image</meta>
</property>
<property name="largeur" type="string" length="5" >
<meta attribute="field-description">La largeur de l'image</meta>
</property>
<many-to-one name="lesTypesImages" column="IMAGE_ID" insert="false" update="false" class="manus.dictionnaire.data.ImageImpl"/>
<joined-subclass name="manus.dictionnaire.data.Dessin" extends="manus.dictionnaire.data.ImageImpl" table="DESSIN">
<meta attribute="class-description">Represente la famille de dessins, d'illustrations
</meta>
<key column="DESSIN_ID" foreign-key="FK1_DESSIN_ID"/>
<many-to-one name="dessinePar"
class="manus.dictionnaire.data.Fournisseur"
column="FOURNISSEUR_ID"
not-null="false"
foreign-key="FK1_CREE_PAR">
<meta attribute="field-description">Le createur de ce dessin </meta>
</many-to-one>
</joined-subclass>
<joined-subclass name="manus.dictionnaire.data.RxDiapo" extends="manus.dictionnaire.data.ImageImpl" table="RX_DIAPO">
<meta attribute="class-description">Represente la famille d'images Rayons-X ou diapos i.e. de patients
</meta>
<key column="RX_DIAPO_ID" foreign-key="FK1_RX_DIAPO_ID"/>
<property name="noDossier" column="NO_DOSSIER" type="string" length="20" />
<property name="nomHopital" column="NOM_HOPITAL" type="string" length="40" />
<property name="noAssuranceMaladie" column="NAM" type="string" length="20" />
</joined-subclass>
</class>
<query name="manus.dictionnaire.data.imageParNom">
<![CDATA[
from manus.dictionnaire.data.ImageImpl as image
where upper(image.nomImage) = upper(:nomImage)
]]>
</query>
</hibernate-mapping>
___________
public static ImageImpl getImage(String nomImage, Session session)
throws HibernateException
{
Query query = session.getNamedQuery(
"manus.dictionnaire.data.imageParNom");
query.setString("nomImage", nomImage);
ImageImpl imageTrouve = (ImageImpl)query.uniqueResult();
}
Session session = sessionFactory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
ImageImpl imageToDestroy = getImage("ipd", session);
System.out.println("L'image " + imageToDestroy + " is found. ");
session.delete(imageToDestroy);
System.out.println("L'image " + imageToDestroy + " is supposed to be destroyed. ");
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
_______________
[java] 15:57:24,675 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/u1/prog_java/manusHibernate3/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
[java] L'image manus.dictionnaire.data.Dessin@562036[id=28,nomImage=ipd] is found.
[java] L'image manus.dictionnaire.data.Dessin@562036[id=28,nomImage=ipd] is supposed to be destroyed.
[java] 15:57:32,075 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: null
[java] 15:57:32,082 ERROR JDBCExceptionReporter:58 - failed batch
[java] 15:57:32,102 ERROR AbstractFlushingEventListener:277 - Could not synchronize database state with session
[java] org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
[java] at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
[java] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
[java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
[java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
[java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
[java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
[java] at manus.dictionnaire.action.Quest4.main(Quest4.java:189)
[java] Caused by: java.sql.BatchUpdateException: failed batch
[java] at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
[java] at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
[java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
[java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
[java] ... 8 more
[java] La transaction est rollback
[java] Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
[java] at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
[java] at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
[java] at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
[java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
[java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
[java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
[java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
[java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
[java] at manus.dictionnaire.action.Quest4.main(Quest4.java:189)
[java] Caused by: java.sql.BatchUpdateException: failed batch
[java] at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
[java] at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
[java] at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
[java] at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
[java] ... 8 more
[java] Java Result: 1
|