Hibernate使用之:处理clob类型

方法较多,其中之一是:
1.Model中的数据成员类型为String,映射的数据库字段类型为org.springframework.orm.hibernate.support.ClobStringType
/**
 * 电影信息Model 
 */
@Entity
@Table(name = "BK_CTT_MOVIE")
@SuppressWarnings("serial")
public class MovieModel extends BaseModel implements Serializable {
    @Id
    private long id;
    @Column(name = "STARS")
    @Type(type="org.springframework.orm.hibernate3.support.ClobStringType")
    private String stars;

    ....get/set方法
}



2.如果使用spring的这个clob类型就需要在applicationContext.xml中的sessionFactory里修改如下配置
....
<bean id="oracleLobHandler" 
      class="org.springframework.jdbc.support.lob.OracleLobHandler" 
      lazy-init="true">  
    <property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" />
</bean>    
	
<bean id="nativeJdbcExtractor" 
      class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
      lazy-init="true" />  

<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:hibernate/hibernate.cfg.xml" />
    <property name="hibernateProperties">
        <value>
	    hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
	    hibernate.query.substitutions=true 'Y', false 'N'
	    hibernate.cache.use_second_level_cache=true
	    hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
	    hibernate.jdbc.fetch_size=50
	    hibernate.jdbc.use_streams_for_binary=true
	    hibernate.show_sql=true
	</value>
    </property>
    <property name="lobHandler" ref="oracleLobHandler" />
</bean>
....

3.采用oracle thin方式连接的情况下都有传输限制,解决方法是采用oci连接方式(jdbc:oracle:oci10:@sid)

你可能感兴趣的:(spring,oracle,Hibernate,jdbc,cache)