55
55
import org .springframework .core .task .AsyncTaskExecutor ;
56
56
import org .springframework .dao .DataAccessException ;
57
57
import org .springframework .dao .support .PersistenceExceptionTranslator ;
58
- import org .springframework .util .Assert ;
59
58
import org .springframework .util .ClassUtils ;
60
59
import org .springframework .util .CollectionUtils ;
61
60
@@ -264,8 +263,8 @@ public void setJpaVendorAdapter(JpaVendorAdapter jpaVendorAdapter) {
264
263
}
265
264
266
265
/**
267
- * Return the JpaVendorAdapter implementation for this
268
- * EntityManagerFactory, or {@code null} if not known.
266
+ * Return the JpaVendorAdapter implementation for this EntityManagerFactory,
267
+ * or {@code null} if not known.
269
268
*/
270
269
public JpaVendorAdapter getJpaVendorAdapter () {
271
270
return this .jpaVendorAdapter ;
@@ -317,33 +316,46 @@ public void setBeanName(String name) {
317
316
318
317
319
318
@ Override
320
- public final void afterPropertiesSet () throws PersistenceException {
321
- if (this .jpaVendorAdapter != null ) {
319
+ public void afterPropertiesSet () throws PersistenceException {
320
+ JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter ();
321
+ if (jpaVendorAdapter != null ) {
322
322
if (this .persistenceProvider == null ) {
323
- this .persistenceProvider = this . jpaVendorAdapter .getPersistenceProvider ();
323
+ this .persistenceProvider = jpaVendorAdapter .getPersistenceProvider ();
324
324
}
325
- Map <String , ?> vendorPropertyMap = this .jpaVendorAdapter .getJpaPropertyMap ();
326
- if (vendorPropertyMap != null ) {
325
+ PersistenceUnitInfo pui = getPersistenceUnitInfo ();
326
+ Map <String , ?> vendorPropertyMap = null ;
327
+ if (pui != null ) {
328
+ try {
329
+ vendorPropertyMap = jpaVendorAdapter .getJpaPropertyMap (pui );
330
+ }
331
+ catch (AbstractMethodError err ) {
332
+ // Spring 4.3.13 getJpaPropertyMap(PersistenceUnitInfo) not implemented
333
+ }
334
+ }
335
+ if (vendorPropertyMap == null ) {
336
+ vendorPropertyMap = jpaVendorAdapter .getJpaPropertyMap ();
337
+ }
338
+ if (!CollectionUtils .isEmpty (vendorPropertyMap )) {
327
339
for (Map .Entry <String , ?> entry : vendorPropertyMap .entrySet ()) {
328
340
if (!this .jpaPropertyMap .containsKey (entry .getKey ())) {
329
341
this .jpaPropertyMap .put (entry .getKey (), entry .getValue ());
330
342
}
331
343
}
332
344
}
333
345
if (this .entityManagerFactoryInterface == null ) {
334
- this .entityManagerFactoryInterface = this . jpaVendorAdapter .getEntityManagerFactoryInterface ();
346
+ this .entityManagerFactoryInterface = jpaVendorAdapter .getEntityManagerFactoryInterface ();
335
347
if (!ClassUtils .isVisible (this .entityManagerFactoryInterface , this .beanClassLoader )) {
336
348
this .entityManagerFactoryInterface = EntityManagerFactory .class ;
337
349
}
338
350
}
339
351
if (this .entityManagerInterface == null ) {
340
- this .entityManagerInterface = this . jpaVendorAdapter .getEntityManagerInterface ();
352
+ this .entityManagerInterface = jpaVendorAdapter .getEntityManagerInterface ();
341
353
if (!ClassUtils .isVisible (this .entityManagerInterface , this .beanClassLoader )) {
342
354
this .entityManagerInterface = EntityManager .class ;
343
355
}
344
356
}
345
357
if (this .jpaDialect == null ) {
346
- this .jpaDialect = this . jpaVendorAdapter .getJpaDialect ();
358
+ this .jpaDialect = jpaVendorAdapter .getJpaDialect ();
347
359
}
348
360
}
349
361
@@ -372,8 +384,9 @@ private EntityManagerFactory buildNativeEntityManagerFactory() {
372
384
throw new IllegalStateException (
373
385
"JPA PersistenceProvider returned null EntityManagerFactory - check your JPA provider setup!" );
374
386
}
375
- if (this .jpaVendorAdapter != null ) {
376
- this .jpaVendorAdapter .postProcessEntityManagerFactory (emf );
387
+ JpaVendorAdapter jpaVendorAdapter = getJpaVendorAdapter ();
388
+ if (jpaVendorAdapter != null ) {
389
+ jpaVendorAdapter .postProcessEntityManagerFactory (emf );
377
390
}
378
391
if (logger .isInfoEnabled ()) {
379
392
logger .info ("Initialized JPA EntityManagerFactory for persistence unit '" + getPersistenceUnitName () + "'" );
@@ -390,8 +403,9 @@ private EntityManagerFactory buildNativeEntityManagerFactory() {
390
403
*/
391
404
protected EntityManagerFactory createEntityManagerFactoryProxy (EntityManagerFactory emf ) {
392
405
Set <Class <?>> ifcs = new LinkedHashSet <Class <?>>();
393
- if (this .entityManagerFactoryInterface != null ) {
394
- ifcs .add (this .entityManagerFactoryInterface );
406
+ Class <?> entityManagerFactoryInterface = this .entityManagerFactoryInterface ;
407
+ if (entityManagerFactoryInterface != null ) {
408
+ ifcs .add (entityManagerFactoryInterface );
395
409
}
396
410
else if (emf != null ) {
397
411
ifcs .addAll (ClassUtils .getAllInterfacesForClassAsSet (emf .getClass (), this .beanClassLoader ));
@@ -406,8 +420,8 @@ else if (emf != null) {
406
420
new ManagedEntityManagerFactoryInvocationHandler (this ));
407
421
}
408
422
catch (IllegalArgumentException ex ) {
409
- if (this . entityManagerFactoryInterface != null ) {
410
- throw new IllegalStateException ("EntityManagerFactory interface [" + this . entityManagerFactoryInterface +
423
+ if (entityManagerFactoryInterface != null ) {
424
+ throw new IllegalStateException ("EntityManagerFactory interface [" + entityManagerFactoryInterface +
411
425
"] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the " +
412
426
"'entityManagerFactoryInterface' property to plain [javax.persistence.EntityManagerFactory]" , ex );
413
427
}
@@ -485,7 +499,8 @@ else if (method.getName().equals("createEntityManager") && args != null && args.
485
499
*/
486
500
@ Override
487
501
public DataAccessException translateExceptionIfPossible (RuntimeException ex ) {
488
- return (this .jpaDialect != null ? this .jpaDialect .translateExceptionIfPossible (ex ) :
502
+ JpaDialect jpaDialect = getJpaDialect ();
503
+ return (jpaDialect != null ? jpaDialect .translateExceptionIfPossible (ex ) :
489
504
EntityManagerFactoryUtils .convertJpaAccessExceptionIfPossible (ex ));
490
505
}
491
506
0 commit comments