Reputation: 25
I'm using Quarkus with hibernate-panache-orm. Below is my sample code
Optional<OtherObject> opt = object.getList().stream().filter(predicate).findFirst();
if(opt.isPresent()){
OtherObject obj = opt.get()
obj.setVal("SomeVal");
opt.persistAndFlush();
}
If I pass actual values for object
from test class to main class, then opt.persistAndFlush()
step will fail. Else not understanding how to mock .filter(predicate)
step.
Please help. Thanks in Advance
Upvotes: 0
Views: 384
Reputation: 173
I think your intent here is to update the object. Currently you are trying to persist the Optional which is not an Entity and cannot become a Managed Entity.
In this case just change
opt.persistAndFlush();
to
obj.persistAndFlush();
Upvotes: 1