Thursday, May 19, 2011

Spring with Hibernate configuration

Loads object from the data source
<bean id="someRepository">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

Instructs the container to look for beans with @Transactional and decorate them
<tx:annotation-driven transaction-manager="transactionManager"/>


A Hibernate SessionFactory for mapping entities from object to relation tables
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
   <property name="dataSource" ref="dataSource"/>
   <property name="annotatedClasses">
      <list>
         <value>package.Entity1</value>
         <value>package.Entity2</value>
      </list>
   </property>
   <property name="hibernateProperties">
      <value>
         hibernate.format_sql=true
         hibernate.show_sql=true
      </value>
   </property>
</bean>


A transaction manager for working with Hibernate SessionFactories
<bean id="transactionManager"  
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

Transparent Exception Handling
Annotate classes with @Repository

No comments:

Post a Comment