Closed
Description
If you declare audit annotation like @CreatedBy
in an embedded java record then an exception is thrown :
IllegalState Cannot set property createdUser because no setter, no wither and it's not part of the persistence constructor public springdata.jdbc.bug.UserAudit(java.lang.String,java.time.Instant,java.lang.String,java.time.LocalDateTime)
This issue also happens for other audit annotation @LastModifiedBy,
@LastModifiedDate
and @CreatedDate
If the annotation are not in an embedded object it's work.
Exemple of code to reproduce issue
public record Car (
@Id Long id,
String name,
@Embedded.Empty()
UserAudit userAudit
){}
public record UserAudit(@LastModifiedBy String modifiedUser,
@LastModifiedDate Instant modifiedDate,
@CreatedBy String createdUser,
@CreatedDate LocalDateTime createdDate) {}
CREATE TABLE IF NOT EXISTS Car (
id INTEGER IDENTITY PRIMARY KEY,
name VARCHAR(100),
-- UserAudit attributes
modified_user varchar(255),
modified_date timestamp,
created_user varchar(255),
created_date timestamp
);
Here a project to reproduce the bug (the test failed) : https://github.com/jipipi/spring-data-jdbc-bug1
spring-data-jdbc : 3.2.0
java 17