I'm pretty new to both Hibernate and Blob's, so this question of mine might seem strange.
What I'm planning to do is the following:
- create a pojo that has a byte[] field;
- create a corresponding hbm that has that field as a blobAsByteArray type;
- introduce a local class BlobAsByteArray that implements hibernate's UserType;
- have that class either use net.sf.beanlib.utils.BlobUtils's methods or Hibernate3BeanTransformer (not sure here).
My question: Am I on the right track here or am I overlooking something.
Thanx!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
However, I'd like to have my pojo's really clean so I can basically create them on the spot from the hbm. I don't have enough background so that I can say "that's what I want" or, "you shouldn't want that". So I want to keep my options open. Besides, it's very possible that I have more blob's in future projects.
So I figured that implementing usertype could lead to a re-usable and cleaner solution, and have a go at that.
Also, I read in "Hibernate In Action" that the authors had found the database-drivers behave very differently. Hibernate knows all, which is really great! When I started looking for a Blob solution I first found http://www.hibernate.org/73.html, which basically states that this isn't as easy as it should be, and got me on alert. I'm not so eager of having to do a lot of re-work when the drivers are upgraded. I'm hoping that bean-lib solves all ;)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>I can basically create them on the spot from the hbm
I see.
>So I figured that implementing usertype could lead to a re-usable and cleaner solution, and have a go at that.
Fair enough.
> What I'm planning to do is the following:
> - create a pojo that has a byte[] field;
> - create a corresponding hbm that has that field as a blobAsByteArray type;
> - introduce a local class BlobAsByteArray that implements hibernate's UserType;
> - have that class either use net.sf.beanlib.utils.BlobUtils's methods or
> Hibernate3BeanTransformer (not sure here).
You can convert from Blob to byte[] via BlobUtils.toByteArray(Blob), and the inverse via Hibernate.createBlob(byte[]). Hope this helps.
Please let me know how this is going, and if you can share the solution when found!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi .. i'm using Hibernate, Spring in my application and actually using BlobByteArrayType that Spring provide for blob work, now i'm facing the problem when try to clone my object with Hibernate3BeanReplicator, can anybody help on this, please, i'm staring with this lib and i think is great.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
BlobByteArrayType isn't a JavaBean, so Beanlib won't copy it by default. However, you can consider plugging in your own CustomBeanTransformerSpi to handle this type. Have a look at the junit tests for some samples. Let me know if this works for you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been looking what you told me, but i don't know how to accomplish this, because my POJOS have an byte[], so i don't know the mining of from, toClass in the method isTransform(Object from, Class<T> toClass,PropertyInfo property) of the interface. How can I enhance to BlobByteArrayType. Sorry but the test unit don't help me so much ..
Don't you have a sample of a CustomTransormer that i can use has a guide or something ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have not used BlobByteArrayType before, but it looks like BlobByteArrayType is only specified in your hibernate mapping file, whereas your domain object class is still defined with byte[]. In that case, there should be nothing more you need to do to use Hibernate3BeanReplicator to replicate these objects. I wonder what specific problem you are encountering.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes I realize that it shouldn't be a problem, but is not working, seems like in the ReplicatorTemplate class in the replicate method
if (from.getClass().isArray())
return beanTransformer.getArrayReplicatable().replicateArray((Object[])from, toClass);
Is not working for the Array byte[]
So i implement a CustomBeanTransformerSpi to test this, and when i find a byte[].class then i trying to transform using
beanTransformer.getArrayReplicatable().replicateArray((Object[])in , toClass);
and it throw and Exception java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
And never enter the method replicateArray(V[] array, Class<T> toClass)..
I'm not sure if i can express correctly the problem, but the truth is that the replication for a byte[] is not working, please, can u test it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm pretty new to both Hibernate and Blob's, so this question of mine might seem strange.
What I'm planning to do is the following:
- create a pojo that has a byte[] field;
- create a corresponding hbm that has that field as a blobAsByteArray type;
- introduce a local class BlobAsByteArray that implements hibernate's UserType;
- have that class either use net.sf.beanlib.utils.BlobUtils's methods or Hibernate3BeanTransformer (not sure here).
My question: Am I on the right track here or am I overlooking something.
Thanx!
Have you looked at:
http://hansonchar.blogspot.com/2005/06/oracle-blob-mapped-to-byte-in.html
and the associated comments ?
I haven't tried UserType. If you just need a byte[] member field, you can map it with the "blob" type as suggested in the blog.
Yeah, that's were I got the link to beanlib from. Actually my search started at:
http://www.hibernate.org/73.html
However, I'd like to have my pojo's really clean so I can basically create them on the spot from the hbm. I don't have enough background so that I can say "that's what I want" or, "you shouldn't want that". So I want to keep my options open. Besides, it's very possible that I have more blob's in future projects.
So I figured that implementing usertype could lead to a re-usable and cleaner solution, and have a go at that.
Also, I read in "Hibernate In Action" that the authors had found the database-drivers behave very differently. Hibernate knows all, which is really great! When I started looking for a Blob solution I first found http://www.hibernate.org/73.html, which basically states that this isn't as easy as it should be, and got me on alert. I'm not so eager of having to do a lot of re-work when the drivers are upgraded. I'm hoping that bean-lib solves all ;)
>I can basically create them on the spot from the hbm
I see.
>So I figured that implementing usertype could lead to a re-usable and cleaner solution, and have a go at that.
Fair enough.
> What I'm planning to do is the following:
> - create a pojo that has a byte[] field;
> - create a corresponding hbm that has that field as a blobAsByteArray type;
> - introduce a local class BlobAsByteArray that implements hibernate's UserType;
> - have that class either use net.sf.beanlib.utils.BlobUtils's methods or
> Hibernate3BeanTransformer (not sure here).
You can convert from Blob to byte[] via BlobUtils.toByteArray(Blob), and the inverse via Hibernate.createBlob(byte[]). Hope this helps.
Please let me know how this is going, and if you can share the solution when found!
Hi .. i'm using Hibernate, Spring in my application and actually using BlobByteArrayType that Spring provide for blob work, now i'm facing the problem when try to clone my object with Hibernate3BeanReplicator, can anybody help on this, please, i'm staring with this lib and i think is great.
Thanks
BlobByteArrayType isn't a JavaBean, so Beanlib won't copy it by default. However, you can consider plugging in your own CustomBeanTransformerSpi to handle this type. Have a look at the junit tests for some samples. Let me know if this works for you.
Specifically, you can plug in your CustomBeanTransformerSpi via:
Hibernate3BeanReplicator#initCustomTransformer(CustomBeanTransformerSpi.Factory customTransformerFactory);
I have been looking what you told me, but i don't know how to accomplish this, because my POJOS have an byte[], so i don't know the mining of from, toClass in the method isTransform(Object from, Class<T> toClass,PropertyInfo property) of the interface. How can I enhance to BlobByteArrayType. Sorry but the test unit don't help me so much ..
Don't you have a sample of a CustomTransormer that i can use has a guide or something ?
I have not used BlobByteArrayType before, but it looks like BlobByteArrayType is only specified in your hibernate mapping file, whereas your domain object class is still defined with byte[]. In that case, there should be nothing more you need to do to use Hibernate3BeanReplicator to replicate these objects. I wonder what specific problem you are encountering.
Yes I realize that it shouldn't be a problem, but is not working, seems like in the ReplicatorTemplate class in the replicate method
if (from.getClass().isArray())
return beanTransformer.getArrayReplicatable().replicateArray((Object[])from, toClass);
Is not working for the Array byte[]
So i implement a CustomBeanTransformerSpi to test this, and when i find a byte[].class then i trying to transform using
beanTransformer.getArrayReplicatable().replicateArray((Object[])in , toClass);
and it throw and Exception java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
And never enter the method replicateArray(V[] array, Class<T> toClass)..
I'm not sure if i can express correctly the problem, but the truth is that the replication for a byte[] is not working, please, can u test it.
You are right. I will be releasing beta8 soon to have this bug fixed.
Beanlib 3.3.0beta8 is now available for download. Let me know if this works for you.
Pending maven upload:
http://jira.codehaus.org/browse/MAVENUPLOAD-1655
It works fine, thanks.. by the way great library !!
We keep in touch ..
Bye