MongoDB のトランザクション サポートはまだ実験的な領域であることはわかっていますが、まだ初期段階にあるプロジェクトの 1 つで使用しようとしています。
私はHibernateを使用していないので...次のようにJTA依存関係も追加しました:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-narayana-jta</artifactId>
</dependency>
@Transactional アノテーションを次のように使用しています。
@POST
@Transactional
public Response addServicePlace(@RequestBody(description = "Adds a new record", required = true, content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ServicePlaces.class))) @Valid ServicePlaces services, @Context UriInfo uriInfo) {
Service s = new Service();
s.typeId = services.type;
s.title = services.title;
s.persist();
services.descriptions.stream().forEach(c -> {
ServiceDescription serviceDescription = new ServiceDescription();
serviceDescription.lang = c.lang;
serviceDescription.description = c.description;
serviceDescription.serviceId = s.id;
serviceDescription.persist();
});
throw new RuntimeException("BANG!"); ....
ただし、トランザクションはロールバックされません。
私は宣言的なトランザクション実装も使用しました-同じ動作です。
参考までに、私は Panache の Active Record Pattern を使用しています。
誰かが同様のシナリオに直面しましたか?