I am building a cache of objects and trying to persist them as I receive them in my DB (Stripe Webhooks if your familiar). But for some reason I cannot get any of them to persist, though there are no errors thrown....
NOTE: don't let the GET confuse you I changed it to GET so I could test it easier.... it will be a POST if it ever works (yeah I'm a little frustrated been trying different variations all weekend. not sure if its just me but this stuff seems really poorly defined, you can find a half dozen articles all giving me different approaches)
@Path("/events/{realm}/add")
@GET
@ReactiveTransactional
public Uni<Response> add(@PathParam("realm") String realm, @QueryParam("id") String id) {
return Panache.withTransaction(() -> StripeAccount.findRealm(realm)
.onItem().transform(a -> new StripeCustomer(realm,id)).onItem().invoke(e -> e.persist())
).onItem().ifNotNull().transform(e -> Response.ok(e).build())
.onItem().ifNull().continueWith(Response.ok().status(NOT_FOUND)::build);
}
I have tried the above endpoint with and without the ReactiveTransactional and with and without the "withTransaction()" but it never persists in mysql DB though the new object is returned in the response and no errors are thrown.
@Entity
@Table(name="Customers")
public class StripeCustomer extends PanacheEntityBase {
@Id
@Column(name = "cust_id")
public String id;
@Column(name = "cust_realm")
public String realm;
public StripeCustomer(String realm, String id) {
this.realm = realm;
this.id = id;
}
}
The ID is a natural key I receive from Stripe and I do not know if this is part of the problem. I have tried designating the @Id differently as well but nothing seems to help. I also tried extending from PanacheEntity and allowing JPA to create a redundant key but that too did not help.