Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 8ef0865

Browse files
committed
Refine DefaultPersistenceUnitManager substitution predicates
This commit ensures PersistenceException is in the classpath before applying the substitution (otherwise an error is thrown). Closes gh-1500
1 parent bf4f979 commit 8ef0865

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.springframework.nativex.substitutions;
2+
3+
import java.util.function.BooleanSupplier;
4+
5+
public class PersistenceExceptionIsAround implements BooleanSupplier {
6+
7+
@Override
8+
public boolean getAsBoolean() {
9+
try {
10+
Class.forName("javax.persistence.PersistenceException");
11+
return true;
12+
} catch (ClassNotFoundException e) {
13+
return false;
14+
}
15+
}
16+
}

spring-native/src/main/java/org/springframework/nativex/substitutions/framework/Target_DefaultPersistenceUnitManager.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.oracle.svm.core.annotate.TargetClass;
2323

2424
import org.springframework.nativex.substitutions.OnlyIfPresent;
25+
import org.springframework.nativex.substitutions.PersistenceExceptionIsAround;
2526

2627
/**
2728
* Workaround for javax.persistence.PersistenceException: Unable to resolve persistence unit
@@ -30,8 +31,9 @@
3031
* org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)
3132
*
3233
* @author Andy Clement
34+
* @author Sebastien Deleuze
3335
*/
34-
@TargetClass(className = "org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager", onlyWith = OnlyIfPresent.class)
36+
@TargetClass(className = "org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager", onlyWith = { OnlyIfPresent.class, PersistenceExceptionIsAround.class })
3537
final class Target_DefaultPersistenceUnitManager {
3638

3739
@Substitute

0 commit comments

Comments
 (0)