Skip to content

Commit fdd6e50

Browse files
jjanksbrannen
authored andcommitted
Correct not compiling example code in Data Access docs
The EntityManager interface does not implement AutoCloseable until JPA 3.1. This commit therefore partially reverts 189e1af so that the example code compiles with the supported JPA version. See gh-22269 Closes gh-27886
1 parent c04fa85 commit fdd6e50

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/docs/asciidoc/data-access.adoc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,10 +2444,10 @@ the `TransactionOperator` resembles the next example:
24442444
}
24452445
24462446
public Mono<Object> someServiceMethod() {
2447-
2447+
24482448
// the code in this method runs in a transactional context
2449-
2450-
Mono<Object> update = updateOperation1();
2449+
2450+
Mono<Object> update = updateOperation1();
24512451
24522452
return update.then(resultOfUpdateOperation2).as(transactionalOperator::transactional);
24532453
}
@@ -8221,11 +8221,17 @@ that uses the `@PersistenceUnit` annotation:
82218221
}
82228222
82238223
public Collection loadProductsByCategory(String category) {
8224-
try (EntityManager em = this.emf.createEntityManager()) {
8224+
EntityManager em = this.emf.createEntityManager();
8225+
try {
82258226
Query query = em.createQuery("from Product as p where p.category = ?1");
82268227
query.setParameter(1, category);
82278228
return query.getResultList();
82288229
}
8230+
finally {
8231+
if (em != null) {
8232+
em.close();
8233+
}
8234+
}
82298235
}
82308236
}
82318237
----

0 commit comments

Comments
 (0)