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?