1

Client side PK creation is pretty common, especially when using UUIDs as keys. Unfortunately I can't see where this is supported in Spring Data JDBC. I get these errors instead:

Failed to execute DbAction.UpdateRoot(entity=my.agg.root.ClassName@28f2d8e6)

Grepping the Spring Data JDBC source for DbAction.UpdateRoot, I found this in o.s.d.relational.core.Conversion.WritingContext:

    List<DbAction<?>> save() {

        List<DbAction<?>> actions = new ArrayList<>();
        if (isNew(root)) {

            actions.add(setRootAction(new DbAction.InsertRoot<>(entity)));
            actions.addAll(insertReferenced());
        } else {

            actions.add(setRootAction(new DbAction.UpdateRoot<>(entity)));
            actions.addAll(deleteReferenced());
            actions.addAll(insertReferenced());
        }

        return actions;
    }

I didn't dig into isNew(), but if it is a simple null check of my object's @Id field, then maybe the repo will always flag my object as existing, and try and UPDATE rather than an INSERT, if my @Id is set. In which case I'm out of luck.

Should I just write my own @Query method with an INSERT instead, upon object creation?

Thanks!

Bean Taxi
  • 1,104
  • 1
  • 9
  • 22

0 Answers0