Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple TransactionManagers using @Transactional annotation [SPR-5896] #10565

Closed
spring-projects-issues opened this issue Jul 3, 2009 · 2 comments
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Tom Spencer opened SPR-5896 and commented

It would be great to have support for using the @Transactional annotation in a multipe TransactionManager environment, providing declarative transaction demarcation support for multiple SessionFactories. One idea suggested in the forum link is to create the multiple TransactionManager beans in the Application Context XML file, and give them unique names - then add a field to the @Transactional annotation, so we could then reference the TransactionManager by name in the Service method.

For example:

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

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

<tx:annotation-driven>
  <transaction-manager ref="txManager1" />
  <transaction-manager ref="txManager2" />
</tx:annotation-driven>

Then, in the application code:

@Transactional(name="txManager1")
public String getFoo()
{
    return dao.find("foo");
}
@Transactional(name="txManager2")
public String getBar()
{
    return dao.find("bar");
}

Affects: 2.5.6

Reference URL: http://forum.springsource.org/showthread.php?t=27754

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This has already been implemented for Spring 3.0 and is available in recent 3.0 RC1 snapshots: using @Transactional value Strings for differentiating among multiple PlatformTransactionManagers. Feel free to give it an early try :-)

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Tom Spencer commented

Brilliant! One step ahead of the game, as always ;-) Thanks very much for the info, just goes to show I should have read the roadmap before posting.

@spring-projects-issues spring-projects-issues added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 M4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants