-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Transactions in hibernate
PostPosted: Tue Dec 26, 2006 11:34 pm 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
Hi,

I am currently learning hibernate and its transactions - I understand the transaction as a group of operations that have to be performed together, or the so called 'rollback' occurs and in case of some error, everything backups the the previous state - we avoid many problems thanks to that...

I am writing simple application that will use Hibernate3 and i will be an electronic school register with marks from some exams. I know, that it is more like spring question, becouse I use it but still within Hibernate configuration. Is that good way for reaching above goals?

Code:
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd"
   default-lazy-init="true">


<!--
  - Root application context for the Countries application.
  - Web-specific beans are defined in "countries-servlet.xml".
  -->

   <bean id="customerService" class="demo.service.CustomerServiceImpl">
      <property name="customerDao"><ref bean="customerDao"/></property>
   </bean>


   <bean id="customerDao" class="demo.dao.HbCustomerDAO">
      <property name="sessionFactory"><ref bean="sessionFactory"/></property>
   </bean>

   </bean>

   <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
      <property name="beanNames" value="*Service"/>
      <property name="interceptorNames" value="txInterceptor"/>
   </bean>
   
    <bean id="daoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames" value="*Dao"/>
        <property name="interceptorNames" value="txInterceptor"/>
    </bean>
   
   <bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
      <property name="transactionAttributes" value="*:PROPAGATION_REQUIRED"/>
      <property name="transactionManager" ref="transactionManager"/>
   </bean>
 
   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="dataSource"><ref bean="dataSource"/></property>
      <property name="sessionFactory"><ref bean="sessionFactory"/></property>
   </bean>

 
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
         <property name="driverClassName">
            <value>com.p6spy.engine.spy.P6SpyDriver</value>
         </property>
         <property name="url">
            <value>jdbc:mysql://localhost:3308/demo</value>
         </property>
         <property name="username">
            <value>root</value>
         </property>
         <property name="password">
            <value>root</value>
         </property>
  </bean>

  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource"><ref bean="dataSource"/></property>
     <property name="hibernateProperties">
         <util:properties location="hibernate.properties" />
      </property>
      <property name="mappingLocations">
         <list>
            <value>classpath:amg/demo/model/CustomerModel.hbm.xml</value>
            
         </list>
      </property>
  </bean>

</beans>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 5:49 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
Actually, i don't understand your question. If you asked, whether using Hibernate+Spring is a good strategy for managing transactions, my answer is yes. Spring provides declarative transaction demarcation capabilities, easy integration with Hibernate and many other useful things. If your question was about configuration of Spring and Hibernate in applicationContext.xml, it looks like all things right.

_________________
Best Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.