Hi,
I am having a hard time figuring out how Mybatis save and retrieve large object in PostgreSQL.
Any help would be greatly appreciated.
I am using:
MyBatis 3.1.1
PostgreSQL 9.2
PostgreSQL code:
CREATE TABLE file_blob
(
id serial NOT NULL,
data_blob oid NOT NULL
)
Java code:
public class FileEntity{
private int id;
private byte[] fileBytes;
//getters and setters
}
//Also plus DAO and interface mapper
Mapper XML:
<resultMap id="FileEntityResultMap" type="FileEntity">
<result property="id" column="id" />
<!--pretty sure this is wrong, but do not know what it should be-->
<result property="fileBytes" column="data_blob" jdbcType="BINARY" />
</resultMap>
<select id="find" resultMap="FileEntityResultMap">
select id, name, data_blob
from file_blob
where id = #{id};
</select>
<insert id="insert" parameterType="FileEntity" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
insert into file_blob(data_blob)
values( #{fileBytes,jdbcType=BINARY});
</insert>
Error messages:
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.postgresql.util.PSQLException: ERROR: column "data_blob" is of type oid but expression is of type bytea
ヒント: You will need to rewrite or cast the expression.
ポジション: 120
### The error may involve databasetest.mapper.FileEntityMapper.insert-Inline
### The error occurred while setting parameters
### SQL: insert into file_blob( data_blob) values( ? );
### Cause: org.postgresql.util.PSQLException: ERROR: column "data_blob" is of type oid but expression is of type bytea
ヒント: You will need to rewrite or cast the expression.
ポジション: 120
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:147)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
....