-->
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: BLOB is corrupted when loading an entity (using postgres)
PostPosted: Fri Jul 01, 2005 1:50 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
Hi,

I use @Lob to store a password hash in an entity. My problem is that I save 16 bytes, but when the entity is loaded it is only 15 bytes! The first byte is lost!


Details:
I have an entity:

@javax.persistence.Entity
@Entity(dynamicInsert = true, dynamicUpdate = true)
@Table(name = "Users")
public class User extends VersionedPersistentObjectImpl
{
private String userName;

public String getUserName()
{
return userName;
}

public void setUserName(String userName)
{
this.userName = userName;
}

private byte[] passwordHash;

@Lob
@Column(nullable=true)
public byte[] getPasswordHash()
{
return passwordHash;
}

public void setPasswordHash(byte[] passwordHash)
{
this.passwordHash = passwordHash;
}
}

Saving and loading is nothing special. I use Spring's HibernateDaoSupport class to implement DAO functionality.
Before saving I call:

user.setPasswordHash(new byte[] {-44, 29, -116, -39, -113, 0, -78, 4, -23, -128, 9, -104, -20, -8, 66, 126});

But after loading the entity using Session.find()

user.getPasswordHash()

returns [29, -116, -39, -113, 0, -78, 4, -23, -128, 9, -104, -20, -8, 66, 126].
So the first byte is lost, the rest is OK!


I use 3.1a1 with annotations 3.1b3 with postgres 8.0.

Someone please help me in this one!!!

Br,
Norbi


Top
 Profile  
 
 Post subject: comparing with SQL
PostPosted: Fri Jul 01, 2005 2:12 am 
Newbie

Joined: Fri Apr 02, 2004 9:57 am
Posts: 14
When I use

ResultSet rs = st
.executeQuery("select passwordHash from users where username='admin'");

if (rs.next())
{
Blob blob = rs.getBlob(1);
byte[] bytes = blob.getBytes(0, (int)blob.length());
}


then it returns all 16 bytes!
So it doesn't seem to be a problem with postgres/jdbc.

Br,
Norbi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 01, 2005 9:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes there is a bug in the postgres driver. It is fixed in their CVS though.

_________________
Emmanuel


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.