【问题标题】:Building Application with Spring MVC/Hibernate using HibernateTransactionManager使用 HibernateTransactionManager 使用 Spring MVC/Hibernate 构建应用程序
【发布时间】:2010-11-02 10:55:02
【问题描述】:

据我了解,不建议在 Spring 中使用 HibernateTemplate。 所以我想要做的是使用 HibernateTransactionManager 编写它: 到目前为止我所做的是数据库和会话初始化

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="org.postgresql.Driver" />
  <property name="url" value="jdbc:postgresql://127.0.0.1/doolloop2" />
  <property name="username" value="doolloop2" />
  <property name="password" value="doolloop" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
     <property name="mappingLocations">
      <list>
        <value>WEB-INF/mapping/User.hbm.xml</value>
      </list>
    </property>
    <property name="hibernateProperties">
 <props>
  <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
  <prop key="hibernate.show_sql">true</prop> 
  <prop key="hibernate.hbm2ddl.auto">update</prop> 
  </props>
  </property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>   

接下来是什么? hos 我应该创建我的课程,我应该将其注册为 bean 吗?是否应该使用@Authwired 注释。我有 HibernateTamplate 工作示例,但我想构建新示例。

提前谢谢你.....

【问题讨论】:

标签: java hibernate spring-mvc


【解决方案1】:

一切就绪 - 只需将您的 sessionFactory 注入您的 bean 并操作您的数据。使用 @Transactional 注释来注释您的数据访问方法 - 检查 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-annotations

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-03
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多