-->
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: how to insert blobs in db with hibernate?
PostPosted: Mon Aug 09, 2004 3:29 pm 
Newbie

Joined: Fri Aug 06, 2004 9:44 am
Posts: 11
Hi everybody,
i'm trying to insert a blob type into a database using this class:

public class BinaryBlobType implements UserType
{
public int[] sqlTypes()
{
return new int[] { Types.BLOB };
}

public Class returnedClass()
{
return byte[].class;
}

public boolean equals(Object x, Object y)
{
return (x == y)
|| (x != null
&& y != null
&& java.util.Arrays.equals((byte[]) x, (byte[]) y));
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException
{
Blob blob = rs.getBlob(names[0]);
return blob.getBytes(1, (int) blob.length());
}

public void nullSafeSet(PreparedStatement st, Object value, int index)
throws HibernateException, SQLException
{
st.setBlob(index, Hibernate.createBlob((byte[]) value));
}

public Object deepCopy(Object value)
{
if (value == null) return null;

byte[] bytes = (byte[]) value;
byte[] result = new byte[bytes.length];
System.arraycopy(bytes, 0, result, 0, bytes.length);

return result;
}

public boolean isMutable()
{
return true;
}

}

In method nullSafeSet i can't understand what is the meaning of parameter [b]Object value[/b]

Can someone give me an example to store a blob in db with this method ?

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 09, 2004 5:07 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
I dunno what db you are using.. What happened to the template for a new post?

at any rate, search for blob

and look here too: http://forum.hibernate.org/viewtopic.ph ... light=blob

_________________
--------------------------------------------------
To code or not to code... Is that a question?
--------------------------------------------------
Pritpal Dhaliwal


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 3:28 am 
Newbie

Joined: Fri Aug 06, 2004 9:44 am
Posts: 11
Sorry, i'm using SAP DB

Max


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.