深入浅出Hibernate之向Mysql插入BLOB,CLOB数据
mysql version 5.0
database name:sample
数据表DDL:
create table `sample`.`tuser_blob`(
`id` int not null auto_increment,
`name` varchar(50),
`age` int,
`versio` int,
`user_type` int,
`image` blob,
`resume` mediumblob,
primary key (`id`)
);
TuserBlob.hbm.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="org.hibernatetest.bean.TuserBlob" table="tuser_blob">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
<property name="name" type="java.lang.String">
<column name="name" length="50" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
<property name="versio" type="java.lang.Integer">
<column name="versio" />
</property>
<property name="userType" type="java.lang.Integer">
<column name="user_type" />
</property>
<property name="image" type="java.sql.Blob">
<column name="image" />
</property>
<property name="resume" type="java.sql.Clob">
<column name="resume" />
</property>
</class>
</hibernate-mapping>
对应的java文件:
package org.hibernatetest.bean;
/**
* TuserBlob generated by MyEclipse - Hibernate Tools
*/
import java.sql.Blob;
import java.sql.Clob;
public class TuserBlob implements java.io.Serializable {
// Fields
private Integer id;
private String name;
private Integer age;
private Integer versio;
private Integer userType;
private Blob image;
private Clob resume;
// Constructors