This is not possible in Lombok. Although it would be a really nice feature, it requires resolution to find the constructors of the super class. The super class is only known by name the moment Lombok gets invoked. Using the import statements and the classpath to find the actual class is not trivial. And during compilation you cannot just use reflection to get a list of constructors.
It is not entirely impossible but the results using resolution in val and @ExtensionMethod have taught us that is it hard and error-prone.
Disclosure: I am a Lombok developer.
Answer from Roel Spilker on Stack OverflowAllArgsConstructor does not utilize superclass fields
Making lombak @data work with inheritance
@InheritConstructors to inherit constructors (especially useful for Exception classes)
`[AllArgsConstructor]` with inheritance
This is not possible in Lombok. Although it would be a really nice feature, it requires resolution to find the constructors of the super class. The super class is only known by name the moment Lombok gets invoked. Using the import statements and the classpath to find the actual class is not trivial. And during compilation you cannot just use reflection to get a list of constructors.
It is not entirely impossible but the results using resolution in val and @ExtensionMethod have taught us that is it hard and error-prone.
Disclosure: I am a Lombok developer.
Version 1.18 of Lombok introduced the @SuperBuilder annotation. We can use this to solve our problem in a simpler way.
You can refer to https://www.baeldung.com/lombok-builder-inheritance#lombok-builder-and-inheritance-3.
so in your child class, you will need these annotations:
@Data
@SuperBuilder
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
in your parent class:
@Data
@SuperBuilder
@NoArgsConstructor
Hi,
I am using hibernate with my spring boot application. For columns like updatedAt, createdAt etc, I used an audit class, and then inherited the same class to all my entities.
Now I am trying to access updatedAt as entity.getUpdatedAt() but turns out it doesnt work that way!
Both the parent and child are annotated with "@data", "@AllArgsConstructor" and the entity (child) is annotated with "@EqualsAndHashCode(callSuper=true)".
(I was trying out any solution I could think of or see in stackoverflow - nothingworked.obvious).
How do I make this work? needing inheritance to be supported sounds like such a "everyone should have done it " case but I cant find a working solution! I also read in one answer that you need to annotate the annotation ("@data") so this case is not possible (really?)