• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Spring - Hiber. Transaction is not working...

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a problem with Spring and Hibernate. I have defined a facade and some DAO�s with a transactional behaviour, but they�re not working in a transactional way.

This is my Spring applicationContex:

...

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="MyDataSource"/></property>
<property name="mappingResources">
<list>
....
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">...</prop>
<prop key="hibernate.show_sql">..</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<!-- DAO�S -->
<bean id="UserDao" class="com.....UserDaoImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<bean id="PlantaDao" class="com.....PlantaDaoImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

... more Dao�s ...


<bean id="FacadeDaoTarget" class="....FacadeDaoImpl">
<property name="userDao">
<ref local="UserDao"/>
</property>
<property name="plantaDao">
<ref local="PlantaDao"/>
</property>
... more Dao�s ...
</bean>

<bean id="MyTransactionalDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="FacadeDaoTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<!-- Transaccionales -->
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>


Well, I think that�s OK configured, but when I execute a transactional operation against any DAO, that is not transactional at all.

For example, in UserDaoImpl:

public Long saveUser(User user, Work work) throws DataAccessException, java.sql.SQLException
{
Long id = (Long)getHibernateTemplate().save(user);
if(true) throw new SqlException("My Exception");
}

If I force to fail it, the user is saved. Even if i don�t cast any exception and the method fails due to a real exception, there is not Transacional behaviour.


Please help...
What I�m doing wrong??
Can you help me??

Thanks in advance and forgive my terrible English
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!