Avoid invalid usage of entities due to the need of a default constructor
Closed this issue · 1 comments
Entities need a default constructor to satisfy JPA requirements. Those are currently declared in protected scope which exposes them to potential extensions. E.g. if a special Product
is created, their constructor might call super()
and thus create an invalid instance.
We should try to make the constructor private and see whether Hibernate works with that. If not, we could still resort to an @PrePersist
annotated method that verifies the invariants again.
Private constructors don't really work as the subclasses need to have a default constructor as well and need to be able to call another one. We're going with the @PrePersist
annotated verification method now and also deprecate all no-arg constructors that Salespoint entities expose.