RE: MyBatis and Blobs

194 views
Skip to first unread message
Message has been deleted

Poitras Christian

unread,
Sep 9, 2010, 9:18:02 AM9/9/10
to mybati...@googlegroups.com
I don't think that MyBatis can convert an Object to an InputStream (BLOB). You may want to use byte[] as your "aBlob" input or supply a TypeHandler to allow MyBatis to convert your object to an InputStream - see CallableStatement.setBlob().
As for the output part, it seems appropriate. MyBatis only seems to have trouble setting parameters in the callable statement.

Christian

-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Jan Žanda
Envoyé : September-09-10 8:50 AM
À : mybatis-user
Objet : MyBatis and Blobs

Hi, I've searched the forum and did not find anything useful.

How do I configure calling stored procedures with blobs as IN and OUT
params?
Here's the XML:

<select id="getBlob" statementType="CALLABLE">
{call
ODS_APPL_PKG.get_blob_by_blob(
#{aBlob,mode=IN,jdbcType=BLOB},
#{bBlob,mode=OUT,jdbcType=BLOB},
)}
</select>


here's the Java:

Iface (I tried File classes as IN/OUT, even simple Object as IN/OUT
types, it did the same):

public interface GetBlobByBlob {
public Object getBlob(@Param("aBlob") Object in,
@Param("bBlob") byte[] out);
}


result:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.NullPointerException
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### Cause: java.lang.NullPointerException
at
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
8)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:
61)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:
53)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:
38)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:
66)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:35)
at $Proxy1.getBlob(Unknown Source)
at cz.trask.pokus.bloby.Caller.call(Caller.java:42)
at cz.trask.pokus.bloby.Caller.main(Caller.java:23)
Caused by: java.lang.NullPointerException
at
org.apache.ibatis.type.UnknownTypeHandler.setNonNullParameter(UnknownTypeHandler.java:
21)
at
org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:
23)
at
org.apache.ibatis.executor.parameter.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:
73)
at
org.apache.ibatis.executor.statement.CallableStatementHandler.parameterize(CallableStatementHandler.java:
64)
at
org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:
43)
at
org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:
56)
at
org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:
40)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:
95)
at
org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:
72)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:
59)
... 7 more


Does anynoe have any idea, what I'm doing wrong? I did not find any
example or documentation, that would help.

Thanks

Honza
Reply all
Reply to author
Forward
0 new messages