Skip to content

BeforeConvertCallback<> not called when persisting nested entity #1328

Closed
@polyoxidonium

Description

@polyoxidonium

Due to different database engines I chose to generate UUID within application and not database so I used this callback method.

So consider entities:

public class Order implements Persistable {

    @Id
    private UUID orderId;
    private OrderType orderType;
    @MappedCollection(idColumn = "order_id")
    private Set<Product> products;
...
}

public class Product implements Persistable {
    @Id
    private UUID productId;
    private String productType;
    private String productName;
    private UUID orderId;
...
}

and callback:

@Component
class EntityCallback implements BeforeConvertCallback<Persistable> {

    @Override
    public Persistable onBeforeConvert(Persistable aggregate) {
        if (aggregate.getEntityId() == null) {
            aggregate.setEntityId(UUID.randomUUID());
        }
        return aggregate;
    }
}

when I execute orderRepository.save(order)
I get following exception
SQLException with SQL state '23502', error code '23502', message [NULL not allowed for column "PRODUCT_ID";

meaning that productId was not generated during callback function (checked via debug)
Is this intended to work like this?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions