hibernate4通过注解方式整合sessionFactory策略
来源:互联网 发布:蜗牛移动 网络 编辑:程序博客网 时间:2024/06/05 23:58
1.首先是在配置文件里面定义sessionFactory,具体配置如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <!-- 加载common-config.properties文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:config/common-config.properties" /> </bean> <!-- 配置数据源 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://127.0.0.1:3306/appeval" /> <property name="username" value="root" /> <property name="password" value="root" /> </bean> <!-- 配置jdbc --> <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置hibernate SessionFactory--> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hiberante.format_sql">true</prop> </props> </property> <property name="configLocations"> <list> <value> classpath*:config/hibernate/hibernate.cfg.xml </value> </list> </property> </bean> <!-- 事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 事务代理类 --> <bean id="transactionBese" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true" abstract="true"> <property name="transactionManager" ref="transactionManager"></property> <property name="transactionAttributes"> <props> <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="modify*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="del*">PROPAGATION_REQUIRED,-Exception</prop> <prop key="get*">PROPAGATION_NEVER</prop> </props> </property> </bean> </beans>2.然后是重点,通过注解将sessionFactory注入到属性中,代码如下:
@Repository("entityDao")public class HbmEntityDaoImpl implements EntityDao {private final Logger logger = Logger.getLogger(HbmEntityDaoImpl.class); @Autowiredprivate SessionFactory sessionFactory;
其他的就可以通过注释进行具体操作了。
0 0
- hibernate4通过注解方式整合sessionFactory策略
- Hibernate4主键生成策略(注解方式)
- Hibernate4主键生成策略(注解方式)
- Hibernate4 获取SessionFactory 的方式
- Hibernate4 获取SessionFactory 的方式
- 继承hibernateDaoSupport之后通过注解方式注入SessionFactory
- 继承hibernateDaoSupport之后通过注解方式注入SessionFactory
- 继承hibernateDaoSupport之后通过注解方式注入SessionFactory
- 通过注解方式向Dao中注入Sessionfactory
- 继承hibernateDaoSupport之后通过注解方式注入SessionFactory
- 通过注解方式向Dao中注入Sessionfactory
- 继承hibernateDaoSupport之后通过注解方式注入SessionFactory
- 通过注解的方式向DAO中注入Sessionfactory
- Spring3与Hibernate4整合,Spring中配置Hibernate基于XML和annotation的sessionFactory方式。
- Spring4+Hibernate4整合,关于获取SessionFactory
- Hibernate4 注解方式注意事项
- Hibernate4 获取SessionFactory 的2种方式
- spring4+hibernate4 基于注解整合
- Android蓝牙开发中遇到的问题
- Java web----POST和GET中文编码问题
- Lucence入门实例
- ural 1073. Square Country 完全背包
- hibernate基于连接表的多对一单向关联
- hibernate4通过注解方式整合sessionFactory策略
- IO复用高级应用:同时处理TCP和UDP服务
- 2015 坚持
- 自定义组件<五>
- git merge commitId 把其他分支的某次提交merge进该分支
- Unrecognized Windows Sockets error 0 JVM_Bind异常解决办法
- 备查ant配置发送邮件
- IIS7.5+Mysql5.6.22+PHP5.6.4安装配置
- 【难】【BET】无重复值的搜索二叉树的插入和删除操作