-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [noob]mappage des bytea avec hibernate et postgresql
PostPosted: Thu Jan 29, 2009 12:41 pm 
Newbie

Joined: Thu Jan 29, 2009 12:30 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2009 1:01 pm 
Newbie

Joined: Thu Jan 29, 2009 12:30 pm
Posts: 4
je viens d'ajouter ces 2 ligne dans le fichier de configuration
Code:
   <property name="hibernate.jdbc.batch_size">0</property>
      
      <property name="hibernate.jdbc.use_streams_for_binary">true</property>
et l'exception a changé
j'ai maintenant l'exception suivante:
Code:
org.postgresql.util.PSQLException: ERREUR: la colonne « img_gallet » est de type bytea mais l'expression est de type bigint

J'avoue que je suis perdu la -_-'' heeeellpppp .


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.