22
22
import javax .persistence .PersistenceException ;
23
23
24
24
import org .apache .commons .logging .LogFactory ;
25
+ import org .apache .openjpa .persistence .FetchPlan ;
25
26
import org .apache .openjpa .persistence .OpenJPAEntityManager ;
26
27
import org .apache .openjpa .persistence .OpenJPAPersistence ;
28
+ import org .apache .openjpa .persistence .jdbc .IsolationLevel ;
29
+ import org .apache .openjpa .persistence .jdbc .JDBCFetchPlan ;
27
30
28
31
import org .springframework .jdbc .datasource .ConnectionHandle ;
29
32
import org .springframework .jdbc .datasource .ConnectionHolder ;
37
40
* {@link org.springframework.orm.jpa.JpaDialect} implementation for Apache OpenJPA.
38
41
* Developed and tested against OpenJPA 2.2.
39
42
*
40
- * @author Costin Leau
41
43
* @author Juergen Hoeller
44
+ * @author Costin Leau
42
45
* @since 2.0
43
46
*/
44
47
@ SuppressWarnings ("serial" )
@@ -48,14 +51,27 @@ public class OpenJpaDialect extends DefaultJpaDialect {
48
51
public Object beginTransaction (EntityManager entityManager , TransactionDefinition definition )
49
52
throws PersistenceException , SQLException , TransactionException {
50
53
51
- super .beginTransaction (entityManager , definition );
52
- OpenJPAEntityManager em = getOpenJPAEntityManager (entityManager );
54
+ OpenJPAEntityManager openJpaEntityManager = getOpenJPAEntityManager (entityManager );
55
+
56
+ if (definition .getIsolationLevel () != TransactionDefinition .ISOLATION_DEFAULT ) {
57
+ // Pass custom isolation level on to OpenJPA's JDBCFetchPlan configuration
58
+ FetchPlan fetchPlan = openJpaEntityManager .getFetchPlan ();
59
+ if (fetchPlan instanceof JDBCFetchPlan ) {
60
+ IsolationLevel isolation = IsolationLevel .fromConnectionConstant (definition .getIsolationLevel ());
61
+ ((JDBCFetchPlan ) fetchPlan ).setIsolation (isolation );
62
+ }
63
+ }
64
+
65
+ entityManager .getTransaction ().begin ();
66
+
53
67
if (!definition .isReadOnly ()) {
54
68
// Like with EclipseLink, make sure to start the logic transaction early so that other
55
69
// participants using the connection (such as JdbcTemplate) run in a transaction.
56
- em .beginStore ();
70
+ openJpaEntityManager .beginStore ();
57
71
}
58
- return new OpenJpaTransactionData (em );
72
+
73
+ // Custom implementation for OpenJPA savepoint handling
74
+ return new OpenJpaTransactionData (openJpaEntityManager );
59
75
}
60
76
61
77
@ Override
0 commit comments