Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Room not finding lombok generated constructor

I'm using lombok to generate constructors, getters and setters for my models. When i try to use lombok to generate the constructor for my entity class, I get this error

Error:(14, 8) error: Entities and Pojos must have a usable public 
constructor. You can have an empty constructor or a constructor whose 
parameters match the fields (by name and type).
Tried the following constructors but they failed to match:
Region(int,java.lang.String,java.lang.String) -> [param:arg0 -> matched 
field:unmatched, param:arg1 -> matched field:unmatched, param:arg2 -> 
matched field:unmatched]

but writing the constructor manually works. Can anyone help me figure out what's wrong?

My entity class is shown below

@Value
@Entity
public class Region {
    @PrimaryKey
    private int regionId;
    private String name;
    private String code;
}

Room version: 1.1.0 Lombok version: 1.16.20

like image 324
Edwin Nyawoli Avatar asked May 04 '26 23:05

Edwin Nyawoli


1 Answers

The matching seems to fail because the constructor parameter names are not available at runtime. Since version 1.16.20 lombok does not generate @ConstructorProperties annotations any more (which would carry those names). Try adding lombok.anyConstructor.addConstructorProperties = true to your lombok.config, and lombok will generate a @ConstructorProperties annotation for your constructor. (See https://projectlombok.org/features/configuration for details on how to configure lombok.)

EDIT: The problem is the annotation processing during compilation. Both Room and lombok hook into javac as annotation processors, and they do not work nicely in combination. So at the moment, the only stable solution is to delombok first.

like image 91
Jan Rieke Avatar answered May 07 '26 12:05

Jan Rieke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!