Announcement Announcement Module
Collapse
No announcement yet.
Hibernat4 - How to force commit inside a @Transactional method Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernat4 - How to force commit inside a @Transactional method

    Hello,
    i have a web app with hibernate 4 integration.
    This is my simple configuration:

    Code:
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/dbtest" />
    		<property name="username" value="dbtest" />
    		<property name="password" value="dbtest" />
    	</bean>
    	
    	<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    		<property name="dataSource" ref="dataSource" />
    		<property name="packagesToScan">
    			<list>
    				<value>com.test.db.entity</value>
    			</list>
    		</property>
    		<property name="mappingResources">
    			<list>
    				<value>com/test/db/entity/queries.hbm.xml</value>
    			</list>
    		</property>
    	</bean>
    		
    	<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionFactory" />
    	</bean>

    I'm using @Transactional annotation to let the framework manages the transaction, however in a particular service I really need to force the commit after an insertion, if something after this fails i can not accept the rollback of transaction.

    I would like if there is a way to control transaction inside a @Transactional method.

    I also thought to remove @Transactional annotation from method but this way all components of the service fails on lazy loads of entities.

    What do you suggest?

  • #2
    Hello

    1) Move from DriverManagerDataSource to C3PO... is much better for production...

    2)

    however in a particular service I really need to force the commit after an insertion, if something after this fails i can not accept the rollback of transaction.
    Could you consider Propagation with the value REQUIRES_NEW?.....
    Check the API for a better understanding

    Comment

    Working...
    X