@@ -117,6 +117,8 @@ public class DefaultPersistenceUnitManager
117117
118118 private DataSource defaultDataSource ;
119119
120+ private DataSource defaultJtaDataSource ;
121+
120122 private PersistenceUnitPostProcessor [] persistenceUnitPostProcessors ;
121123
122124 private LoadTimeWeaver loadTimeWeaver ;
@@ -241,9 +243,9 @@ public DataSourceLookup getDataSourceLookup() {
241243 }
242244
243245 /**
244- * Specify the JDBC DataSource that the JPA persistence provider is supposed
245- * to use for accessing the database if none has been specified in
246- * <code>persistence.xml</code> .
246+ * Specify the JDBC DataSource that the JPA persistence provider is supposed to use
247+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
248+ * This variant indicates no special transaction setup, i.e. typical resource-local .
247249 * <p>In JPA speak, a DataSource passed in here will be uses as "nonJtaDataSource"
248250 * on the PersistenceUnitInfo passed to the PersistenceProvider, provided that
249251 * none has been registered before.
@@ -254,20 +256,39 @@ public void setDefaultDataSource(DataSource defaultDataSource) {
254256 }
255257
256258 /**
257- * Return the JDBC DataSource that the JPA persistence provider is supposed
258- * to use for accessing the database if none has been specified in
259- * <code>persistence.xml</code>.
259+ * Return the JDBC DataSource that the JPA persistence provider is supposed to use
260+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
260261 */
261262 public DataSource getDefaultDataSource () {
262263 return this .defaultDataSource ;
263264 }
264265
266+ /**
267+ * Specify the JDBC DataSource that the JPA persistence provider is supposed to use
268+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
269+ * This variant indicates that JTA is supposed to be used as transaction type.
270+ * <p>In JPA speak, a DataSource passed in here will be uses as "jtaDataSource"
271+ * on the PersistenceUnitInfo passed to the PersistenceProvider, provided that
272+ * none has been registered before.
273+ * @see javax.persistence.spi.PersistenceUnitInfo#getJtaDataSource()
274+ */
275+ public void setDefaultJtaDataSource (DataSource defaultJtaDataSource ) {
276+ this .defaultJtaDataSource = defaultJtaDataSource ;
277+ }
278+
279+ /**
280+ * Return the JTA-aware DataSource that the JPA persistence provider is supposed to use
281+ * for accessing the database if none has been specified in <code>persistence.xml</code>.
282+ */
283+ public DataSource getDefaultJtaDataSource () {
284+ return this .defaultJtaDataSource ;
285+ }
286+
265287 /**
266288 * Set the PersistenceUnitPostProcessors to be applied to each
267289 * PersistenceUnitInfo that has been parsed by this manager.
268- * <p>Such post-processors can, for example, register further entity
269- * classes and jar files, in addition to the metadata read in from
270- * <code>persistence.xml</code>.
290+ * <p>Such post-processors can, for example, register further entity classes and
291+ * jar files, in addition to the metadata read from <code>persistence.xml</code>.
271292 */
272293 public void setPersistenceUnitPostProcessors (PersistenceUnitPostProcessor ... postProcessors ) {
273294 this .persistenceUnitPostProcessors = postProcessors ;
@@ -342,6 +363,9 @@ public void preparePersistenceUnitInfos() {
342363 if (pui .getPersistenceUnitRootUrl () == null ) {
343364 pui .setPersistenceUnitRootUrl (determineDefaultPersistenceUnitRootUrl ());
344365 }
366+ if (pui .getJtaDataSource () == null ) {
367+ pui .setJtaDataSource (this .defaultJtaDataSource );
368+ }
345369 if (pui .getNonJtaDataSource () == null ) {
346370 pui .setNonJtaDataSource (this .defaultDataSource );
347371 }
0 commit comments