@@ -34,6 +34,9 @@ import javax.persistence.EntityManager
34
34
*/
35
35
class TestDataLoader {
36
36
37
+ /**
38
+ * Defines the transaction type that the {@link EntityManager} passed to the {@code TestDataLoader } is configured with.
39
+ */
37
40
public enum TransactionType {
38
41
RESOURCE_LOCAL , JTA
39
42
}
@@ -46,16 +49,33 @@ class TestDataLoader {
46
49
private TransactionType transactionType;
47
50
48
51
/**
49
- * Create a new TestDataLoader that uses the specified JPA EntityManager to save and delete entities.
50
- * The EntityManager is expected to be fully initialized and ready to use.
52
+ * Creates a new TestDataLoader that uses the specified JPA EntityManager to save and delete entities.
53
+ * The EntityManager is expected to be fully initialized and ready to use.<br >
54
+ * <br >
55
+ * The {@code TestDataLoader } will assume a {@code TransactionType.RESOURCE_LOCAL } configuration when created with
56
+ * this constructor and therefore try an manage transactions itself. If this is undesired, e. g. in a container
57
+ * environment with managed persistence, use the {@code TestDataLoader(EntityManager, TransactionType) }
58
+ * constructor with {@code TransactionType.JTA } .
51
59
*
52
60
* @param entityManager {@link EntityManager}
53
61
*/
54
62
TestDataLoader (EntityManager entityManager ) {
55
63
this (entityManager, TransactionType . RESOURCE_LOCAL )
56
64
}
57
65
58
- // TODO: javadoc -> hint that client needs to take care of transaction management when JTA is specified
66
+ /**
67
+ * Creates a new TestDataLoader that uses the specified JPA EntityManager to save and delete entities.
68
+ * The EntityManager is expected to be configured with the specified transaction type and to be fully initialized
69
+ * and ready to use.<br >
70
+ * <br >
71
+ * Note that when specifying {@code TransactionType.RESOURCE_LOCAL }, the {@code TestDataLoader } will try and manage
72
+ * transactions itself. This might not be desired and even lead to runtime exceptions, e. g. in a container
73
+ * environment with managed persistence. Specify {@code TransactionType.JTA } in this case, the {@code TestDataLoader }
74
+ * will assume transactions to be managed by client code then.
75
+ *
76
+ * @param entityManager {@link EntityManager}
77
+ * @param transactionType {@link TransactionType}
78
+ */
59
79
TestDataLoader (EntityManager entityManager , TransactionType transactionType ) {
60
80
if (transactionType == null ) throw new IllegalArgumentException (" transactionType must not be null" )
61
81
checkTransactionType(entityManager, transactionType)
0 commit comments