LocalSessionFactoryBean配置:
lobHandler:
nativeJdbcExtractor:
pojo blob字段的xdoclet:
示例代码调用:
引用: |
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="dataSource" /> </property> <property name="lobHandler"> <ref local="oracleLobHandler" /> </property> <property name="mappingResources"> <list>...</list> </property> <property name="hibernateProperties">...</property> </bean> |
lobHandler:
引用: |
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true"> <property name="nativeJdbcExtractor"> <ref local="nativeJdbcExtractor" /> </property> </bean> |
nativeJdbcExtractor:
引用: |
<!--使用dbcp连接池时启用--> <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" lazy-init="true" /> <!--使用websphere连接池时启用 <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.WebSphereNativeJdbcExtractor" lazy-init="true"/> --> |
pojo blob字段的xdoclet:
java代码: |
public Class BinaryFile private byte [ ] content; /** * @hibernate.property * column="content" * type="org.springframework.orm.hibernate.support.BlobByteArrayType" * * @return binary array content */ public byte [ ] getContent ( ) { return content; } |
示例代码调用:
java代码: |
File file = some file get from anywhere......... byte [ ] fileArray = org. springframework. util. FileCopyUtils. copyToByteArray (file ); BinaryFile bFile = new BinaryFile ( ); bFile. setContent (fileArray ); getHibernateTemplate ( ). save (bFile ); |