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 189e1afc6e so that the
example code compiles with the supported JPA version.
See gh-22269
Closes gh-27886
This commit is contained in:
parent
c04fa858fc
commit
fdd6e50721
|
|
@ -2444,10 +2444,10 @@ the `TransactionOperator` resembles the next example:
|
|||
}
|
||||
|
||||
public Mono<Object> someServiceMethod() {
|
||||
|
||||
|
||||
// the code in this method runs in a transactional context
|
||||
|
||||
Mono<Object> update = updateOperation1();
|
||||
|
||||
Mono<Object> update = updateOperation1();
|
||||
|
||||
return update.then(resultOfUpdateOperation2).as(transactionalOperator::transactional);
|
||||
}
|
||||
|
|
@ -8221,11 +8221,17 @@ that uses the `@PersistenceUnit` annotation:
|
|||
}
|
||||
|
||||
public Collection loadProductsByCategory(String category) {
|
||||
try (EntityManager em = this.emf.createEntityManager()) {
|
||||
EntityManager em = this.emf.createEntityManager();
|
||||
try {
|
||||
Query query = em.createQuery("from Product as p where p.category = ?1");
|
||||
query.setParameter(1, category);
|
||||
return query.getResultList();
|
||||
}
|
||||
finally {
|
||||
if (em != null) {
|
||||
em.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
|
|
|||
Loading…
Reference in New Issue