/** * Specify the JDBC DataSource that the JPA persistence provider is supposed * to use for accessing the database. This is an alternative to keeping the * JDBC configuration in {@code persistence.xml}, passing in a Spring-managed * DataSource instead. * <p>In JPA speak, a DataSource passed in here will be used as "nonJtaDataSource" * on the PersistenceUnitInfo passed to the PersistenceProvider, as well as * overriding data source configuration in {@code persistence.xml} (if any). * Note that this variant typically works for JTA transaction management as well; * if it does not, consider using the explicit {@link #setJtaDataSource} instead. * <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b> * @see javax.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource() * @see #setPersistenceUnitManager */ public void setDataSource(DataSource dataSource) { this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource)); this.internalPersistenceUnitManager.setDefaultDataSource(dataSource); }
/** * Specify the JDBC DataSource that the JPA persistence provider is supposed * to use for accessing the database. This is an alternative to keeping the * JDBC configuration in {@code persistence.xml}, passing in a Spring-managed * DataSource instead. * <p>In JPA speak, a DataSource passed in here will be used as "nonJtaDataSource" * on the PersistenceUnitInfo passed to the PersistenceProvider, as well as * overriding data source configuration in {@code persistence.xml} (if any). * Note that this variant typically works for JTA transaction management as well; * if it does not, consider using the explicit {@link #setJtaDataSource} instead. * <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b> * @see javax.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource() * @see #setPersistenceUnitManager */ public void setDataSource(DataSource dataSource) { this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource)); this.internalPersistenceUnitManager.setDefaultDataSource(dataSource); }
/** * Specify the JDBC DataSource that the JPA persistence provider is supposed to use for accessing the database. * * <p> * This is an alternative to keeping the JDBC configuration in {@code persistence.xml}, passing in a Spring-managed * DataSource instead. * </p> * * <p> * In JPA speak, a DataSource passed in here will be used as "nonJtaDataSource" on the PersistenceUnitInfo passed * to the PersistenceProvider, as well as overriding data source configuration in {@code persistence.xml} (if any). * Note that this variant typically works for JTA transaction management as well; if it does not, consider using the * explicit {@link #setJtaDataSource} instead. * </p> * * @param dataSource the DataSource to use for this EntityManagerFactory * * @see javax.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource() * @see {@link DefaultPersistenceUnitManager#setDefaultDataSource(javax.sql.DataSource)} */ public void setDataSource(DataSource dataSource) { persistenceUnitManager.setDefaultDataSource(dataSource); }
@Bean public DefaultPersistenceUnitManager persistenceUnitManager() { DefaultPersistenceUnitManager persistenceUnitManager = new DefaultPersistenceUnitManager(); persistenceUnitManager.setDefaultDataSource(dataSource()); return persistenceUnitManager; }
/** * Specify the JDBC DataSource that the JPA persistence provider is supposed * to use for accessing the database. This is an alternative to keeping the * JDBC configuration in {@code persistence.xml}, passing in a Spring-managed * DataSource instead. * <p>In JPA speak, a DataSource passed in here will be used as "nonJtaDataSource" * on the PersistenceUnitInfo passed to the PersistenceProvider, as well as * overriding data source configuration in {@code persistence.xml} (if any). * Note that this variant typically works for JTA transaction management as well; * if it does not, consider using the explicit {@link #setJtaDataSource} instead. * <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b> * @see javax.persistence.spi.PersistenceUnitInfo#getNonJtaDataSource() * @see #setPersistenceUnitManager */ public void setDataSource(DataSource dataSource) { this.internalPersistenceUnitManager.setDataSourceLookup(new SingleDataSourceLookup(dataSource)); this.internalPersistenceUnitManager.setDefaultDataSource(dataSource); }