Set the JDBC DataSource that this instance should manage transactions for.
The DataSource should match the one used by the Hibernate SessionFactory:
for example, you could specify the same JNDI DataSource for both.
If the SessionFactory was configured with LocalDataSourceConnectionProvider,
i.e. by Spring's LocalSessionFactoryBean with a specified "dataSource",
the DataSource will be auto-detected: You can still explicitly specify the
DataSource, but you don't need to in this case.
A transactional JDBC Connection for this DataSource will be provided to
application code accessing this DataSource directly via DataSourceUtils
or JdbcTemplate. The Connection will be taken from the Hibernate Session.
The DataSource specified here should be the target DataSource to manage
transactions for, not a TransactionAwareDataSourceProxy. Only data access
code may work with TransactionAwareDataSourceProxy, while the transaction
manager needs to work on the underlying target DataSource. If there's
nevertheless a TransactionAwareDataSourceProxy passed in, it will be
unwrapped to extract its target DataSource.
NOTE: For scenarios with many transactions that just read data from
Hibernate's cache (and do not actually access the database), consider using
a
org.springframework.jdbc.datasource.LazyConnectionDataSourceProxyfor the actual target DataSource. Alternatively, consider switching
#setPrepareConnection to
false.
In both cases, this transaction manager will not eagerly acquire a
JDBC Connection for each Hibernate Session anymore (as of Spring 5.1).