-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate, Annotations, PostgreSQL bug in reading BLOBs
PostPosted: Thu Jul 21, 2005 12:08 pm 
Newbie

Joined: Thu Jul 21, 2005 11:39 am
Posts: 1
Hello.
I use:
hibernate-3.0.5
hibernate-annotations-3.1beta3
postgresql-8.0.3 (win32)

the problem: when _reading_ byte[] data from postgres the first byte is truncated. try using hsqldb instead of postgres and everything works fine.

here is the test code:
Code:
import org.hibernate.*;
import org.hibernate.cfg.*;

public class Test
{
   public static void main(String[] args)
   {
      new Test(args);
   }

   public Test(String[] args)
   {
      AnnotationConfiguration ac = new AnnotationConfiguration();
      ac.configure("hibernate.cfg.xml");

      SessionFactory sf = ac.buildSessionFactory();
      Session s = sf.openSession();
      Transaction t = s.beginTransaction();

      Data d = new Data();
      d.setKey("key");
      d.setValue(new String("value").getBytes());
      s.persist(d);

      // note: the bug does not appear if you do not close & reopen the connection
      t.commit();
      s.close();
      s = sf.openSession();
      t = s.beginTransaction();

      d = (Data)s.get(Data.class, "key");
      System.out.println("value: '" + new String(d.getValue()) + "'");

      s.close();
      sf.close();
   }
}


and the persisted class:
Code:
import javax.persistence.*;

@Entity(access = AccessType.FIELD)
public class Data
{
   @Id
   private String key;

   public String getKey()
   {
      return key;
   }

   public void setKey(String key)
   {
      this.key = key;
   }

   @Lob(type = LobType.BLOB)
   private byte[] value;

   public byte[] getValue()
   {
      return value;
   }

   public void setValue(byte[] value)
   {
      this.value = value;
   }
}


some output:
Code:
Hibernate: insert into Data (value, key) values (?, ?)
Hibernate: select data0_.key as key0_, data0_.value as value0_0_ from Data data0_ where data0_.key=?
value: 'alue'


'value' and not 'alue' should be returned.

any1 experienced the same problem?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's a bug in the Postgres driver, it is fixed in their CVS head.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 6:58 am 
Newbie

Joined: Sat Jan 14, 2006 7:36 pm
Posts: 4
You cat write me the steps for fixing the problem?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 1:15 pm 
Regular
Regular

Joined: Sat Jan 07, 2006 8:30 pm
Posts: 68
Get the latest driver and check if that works.


Top
 Profile  
 
 Post subject: Re: Hibernate, Annotations, PostgreSQL bug in reading BLOBs
PostPosted: Thu Jul 01, 2010 6:06 pm 
Beginner
Beginner

Joined: Mon Jun 28, 2010 1:02 pm
Posts: 21
I'm using @Lob annotation and byte[] type in my class. I get an SQL exception when I try to persist the class. WHat extre steps should I take to make this solution work? A simple get/set method is not enough? What can be the problem?
Please visit my topic:
https://forum.hibernate.org/viewtopic.php?f=1&t=1005584


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