共用mybait 和 hibernate 细节

来源:互联网 发布:太平洋软件 编辑:程序博客网 时间:2024/06/17 20:45

在拓胜实训的日子,想到要学mybait 又 要学hibernate 所以 突发奇想 整合 ssmh 吧

1.ssm 原来的搭建方法 我就不多说了

2. 加入hibernate

1.mybait 和 hibernate 共用dataSource

2.mybait 和 hibernate 共用 事务管理 (mybait 原来用springjdbc 的,hibernate用自己的)

(1.共用jdbc 没试)

(2.共用hibernate)

<bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /><property name="dataSource"><ref bean="dataSource" /></property></bean>
<tx:annotation-driven transaction-manager="transactionManager" />


<bean id="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource"><ref bean="dataSource" /></property><property name="packagesToScan"><list><value>com.cn.hanbo.entity</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">true</prop><prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop></props></property><!-- <property name="useTransactionAwareDataSource"><value>true</value></property> --></bean>
注意:

我在事务用hibernate4 工厂也用4 不然一直no session---这个坑 自己没注意 一晚上就没了

0 0
原创粉丝点击