开发者

Building Application with Spring MVC/Hibernate using HibernateTransactionManager

As far as I understand it's not recommended to use HibernateTemplate in Spring. So what I'm trying to to is to write it using HibernateTransactionManager: What I did so far is Database and session initialization

    <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>开发者_StackOverflow社区
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>   

What is next? hos should I create my class and should I register it as beans? should it be using @Authwired annotation. I have HibernateTamplate working example, but I would like to build the new one.

Thank you in Advance.....


You're all set - just inject your sessionFactory in your beans and manipulate your data. Annotate your data access methods with @Transactional annotations - check http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#transaction-declarative-annotations

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜