spring中注入hibernate与ibatis结合使用
1: spring配置文件注入hibernate
<bean id="sessionFactoryFb" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<refbean="dataSource.FF"/>
</property><propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.OracleDialect</prop>
<propkey="hibernate.show_sql">false</prop>
<propkey="hibernate.format_sql">false</prop>
<propkey="hibernate.use_sql_comments">false</prop>
<propkey="hibernate.max_fetch_depth">3</prop>
<propkey="hibernate.default_batch_fetch_size">8</prop>
<propkey="hibernate.order_updates">true</prop>
<propkey="hibernate.transaction.flush_before_completion">
true</prop>
<propkey="hibernate.bytecode.use_reflection_optimizer">
true</prop>
<propkey="hibernate.jdbc.batch_size">50</prop>
</props>
</property><propertyname="mappingResources">
<list>
<value>com/model/oracle/Fb.hbm.xml</value>
</value>
......
</list>
</bean>
2 : 建立 Basedao,作为其他DAO的父类 支持hibernate,ibatis,JdbcTemplate.
public class BaseDao extends HibernateDaoSupport{
protected Log log = LogFactory.getLog(getClass());
protected SqlMapClientTemplate sqlMapClientTemplate = new SqlMapClientTemplate();
protected DataSource dataSource;
protected String dbDialect;
public String getDbDialect() {
return dbDialect;
}
public void setDbDialect(String dbDialect) {
this.dbDialect = dbDialect;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.sqlMapClientTemplate.setDataSource(dataSource);
}
public final DataSource getDataSource() {
return dataSource;
}
public final void setSqlMapClient(SqlMapClient sqlMapClient) {
this.sqlMapClientTemplate.setSqlMapClient(sqlMapClient);
}
public final SqlMapClient getSqlMapClient() {
return this.sqlMapClientTemplate.getSqlMapClient();
}
public final void setSqlMapClientTemplate(
SqlMapClientTemplate sqlMapClientTemplate) {
if (sqlMapClientTemplate == null) {
throw new IllegalArgumentException(
"Cannot set sqlMapClientTemplate to null");
}
this.sqlMapClientTemplate = sqlMapClientTemplate;
}
public final SqlMapClientTemplate getSqlMapClientTemplate() {
return sqlMapClientTemplate;
}
}
3: spring中配置basedao
<bean id="baseDao"
class="com.nstc.fbth.dao.BaseDao">
<propertyname="sessionFactory">
<refbean="sessionFactoryFb"/>
</property>
<propertyname="sqlMapClient">
<reflocal="sqlMapClient"/>
</property>
<propertyname="dataSource">
<refbean="dataSource.FB"/>
</property>
<propertyname="dbDialect">
<value>${sql.server.env}</value>
</property>
</bean>4: 在其他dao中继承basedao即可
<bean id="exchangDao"
class="com.nstc.fbth.dao.ExchangDao"
parent="baseDao" />