-
1. Re: CMP & blob's
car Jul 31, 2003 3:22 PM (in response to car)After many hours investigating this problem I have found a solution myself.
Here the mapping required in standardjbosscmp-jdbc.xml if you want to read and write to blob fields using an byte[] java type rather than some serialized java.lang.Object:
<java-type>[B</java-type>
<jdbc-type>VARBINARY</jdbc-type>
<sql-type>IMAGE</sql-type>
and the entity bean abstract get & set methods will be as below:
public abstract byte[] getField();
public abstract void setField(byte[] value);
Now I can read and write to the blob using array's of bytes just like any byte[] which is simple, neat and tidy coding exercise.
I guess you would need to be a bit careful with really big blobs as when the entity bean is read from the DB it will bring the whole blob into memory and hold it in a byte[].
The <java-type> of '[B' means a byte[] type. This you will not find in any documentation. I found this by looking at the JBoss source code in the process of trying to understand what was going on with blobs. The class in where I found the '[B' is:
org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil
CaR. -
2. Re: CMP & blob's
kentxu May 28, 2004 7:51 PM (in response to car)You can always rely on the container to figure out the java type from your abstract cmp field methods.
The only thing you need to do in jbosscmp-jdbc is to define specific jdbc/sql mapping (without saying anything about the java-type. So "[B" really is optional.
Here is an example in jbosscmp-jdbc.
<cmp-field>
.........
<jdbc-type>VARCHAR</jdbc-type>
<sql-type>BLOB</sql-type>
</cmp-field>