Salut a tous ,
j'ai la table suivante
Code:
CREATE TABLE gallet
(
nom_gallet character varying(20) NOT NULL,
img_gallet bytea,
CONSTRAINT pk_gallet PRIMARY KEY (nom_gallet)
)
mappé par ce code
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="hibernateClass">
<class
name="Gallet"
table="gallet"
>
<meta attribute="sync-DAO">false</meta>
<id
name="nom_gallet"
type="string"
column="nom_gallet"
>
</id>
<property
name="ImgGallet"
column="img_gallet"
type="java.sql.Blob"
not-null="false"
/>
<set name="InfoModeleAvions" inverse="true">
<key column="nom_gallet"/>
<one-to-many class="InfoModeleAvion"/>
</set>
</class>
</hibernate-mapping>
j'ai mis comme type pour imgGallet java.sql.Blob , je ne sais si exact ou pas .
Bref je rencontre une exception lorsque j'essaie d'inserer un gallet dans la table
Code:
Session s=HibernateUtil.currentSession();
Transaction tx = s.beginTransaction();
Gallet g=new Gallet();
File fd = new File("c:\\img.jpg");
FileInputStream fis;
try {
fis = new FileInputStream(fd);
byte[] b = new byte[512];
fis.read(b);
g.setNom_gallet("petit gallet de test");
g.setImgGallet(Hibernate.createBlob(b));
s.save(g);
tx.commit();
HibernateUtil.closeSession();
voila l'exception
Code:
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at mainClass.main(mainClass.java:66)
Caused by: java.sql.BatchUpdateException: L'élément du batch 0 insert into gallet (img_gallet, nom_gallet) values (17027, petit gallet de test) a été annulé. Appeler getNextException pour en connaître la cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2531)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1344)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:343)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2668)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at mainClass.main(mainClass.java:66)
Caused by: java.sql.BatchUpdateException: L'élément du batch 0 insert into gallet (img_gallet, nom_gallet) values (17027, petit gallet de test) a été annulé. Appeler getNextException pour en connaître la cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2531)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1344)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:343)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2668)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
je ne sais si l'erreur provient du fichier de mappage ou de la maniere utilisé pour insérer le blob .
Dans l'exception il me dit que si j'appelle getNextException() je peux connaitre la cause du problème, est ce que vous pouvez m'indiquer comment faire ?
Merci d'avance pour votre aide.
Cordialement.