软件环境:
Spring:2.5.4
Hibernate:3.2.6
Oracle:9i
驱动:ojdbc14.jar
Spring关键配置信息:
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"/> <bean id="oracleLobHandle" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true"> <property name="nativeJdbcExtractor"> <ref local="nativeJdbcExtractor"/> </property> </bean> <!-- 如果是Oracle 10g,则可以直接用 --> <!-- <bean id="oracleLobHandle" lazy-init="true" class="org.springframework.jdbc.support.lob.DefaultLobHandler"/> --> <bean id="sessionFactory" class="com.travelsky.bravo.core.utils.AutoLoadSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect </prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.use_query_cache">false</prop> </props> </property> <property name="lobHandler" ref="oracleLobHandle" /> </bean>
在SessionFactory bean中增加lobHandler属性的使用。
实体类的用法:
@Entity
@Table(name = "ASY_TEST" )
public class TestInfo extends BaseDomain {
private String title;
private String contents;
@Column(name = "TITLE")
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(name = "CONTENTS")
@Type(type="org.springframework.orm.hibernate3.support.ClobStringType")
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
}
数据库字段类型是CLOB
java属性类型是String,需要用org.springframework.orm.hibernate3.support.ClobStringType指定
字段值的存储跟一般字段类型一样。