-->
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.  [ 3 posts ] 
Author Message
 Post subject: [noob]using a bytea with hibernate
PostPosted: Thu Jan 29, 2009 2:42 pm 
Newbie

Joined: Thu Jan 29, 2009 12:30 pm
Posts: 4
Hi ,
I'm using postgreSql 8.3 and i have this table which containt a bytea field .
Code:
CREATE TABLE gallet
(
  nom_gallet character varying(20) NOT NULL,
  img_gallet bytea,
  CONSTRAINT pk_gallet PRIMARY KEY (nom_gallet)
)

hibernate.cfg.xml:
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>

when i try to insert a new gallet
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();

i get this exception
Code:
   
org.postgresql.util.PSQLException: ERROR: column "img_gallet" is a bytea but the expression is a bigint
.....
Caused by: java.sql.BatchUpdateException: The batch of 0 insert into Gallet (img_gallet, nom_gallet) values (17,027 small Gallet test) was canceled. GetNextException call to find out the cause.

can you explain me how to solve this problem ?
Thanks.


Last edited by isoman99 on Thu Jan 29, 2009 5:16 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2009 4:35 pm 
Newbie

Joined: Thu Jan 29, 2009 12:30 pm
Posts: 4
well, the exception is launched weh tx.commit() is called . Any ideas please ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2009 6:20 pm 
Regular
Regular

Joined: Tue Dec 30, 2008 8:14 pm
Posts: 50
I think the mapping type for bytea is "binary", if the java type is byte[].

---
please rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.