如何使用Spring域示例+ Spring域审计



我使用Spring Data Domain Example与实现Spring Data Domain Auditable的实体有以下问题。

错误:org.springframework.dao。InvalidDataAccessApiUsageException:参数值[可选]。[空]不匹配预期的类型[java.time]。LocalDateTime (n/a)];illegalargumentexception:参数值[可选]。[空]不匹配预期的类型[java.time]。LocalDateTime (n/a)]

实体:

import org.springframework.data.domain.Auditable;
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "my_table")
@Builder
public class MyEntity implements Serializable, Auditable<String, Integer, LocalDateTime>
@Getter
@Setter
@Id
@Column(name = "my_table_id", nullable = false)
private Integer id;
// Some fields
// ...
// AUDIT
@Column(name = "my_table_created_by")
@CreatedBy
private String createdBy;

@Column(name = "my_table_created_date")
@CreatedDate
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTime")
private LocalDateTime createdDate;

@Column(name = "my_table_last_modified_by")
@LastModifiedBy
private String lastModifiedBy;

@Column(name = "my_table_last_modified_date")
@LastModifiedDate
@Type(type = "org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTime")
private LocalDateTime lastModifiedDate;

@Override
public boolean isNew()
{
return id == null;
}

@NotNull
@Override
public Optional<String> getCreatedBy()
{
return Optional.ofNullable(createdBy);
}

@Override
public void setCreatedBy(@NotNull String createdBy)
{
this.createdBy = createdBy;
}

@NotNull
@Override
public Optional<LocalDateTime> getCreatedDate()
{
return Optional.ofNullable(createdDate);
}

@Override
public void setCreatedDate(
@NotNull
LocalDateTime creationDate)
{
this.createdDate = creationDate;
}

@NotNull
@Override
public Optional<String> getLastModifiedBy()
{
return Optional.ofNullable(lastModifiedBy);
}

@Override
public void setLastModifiedBy(@NotNull String lastModifiedBy)
{
this.lastModifiedBy = lastModifiedBy;
}

@NotNull
@Override
public Optional<LocalDateTime> getLastModifiedDate()
{
return Optional.ofNullable(lastModifiedDate);
}

@Override
public void setLastModifiedDate(@NotNull LocalDateTime lastModifiedDate)
{
this.lastModifiedDate = lastModifiedDate;
}
}

测试:

import org.springframework.data.domain.Example;
@Test
public void test()
{
MyEntity entity = MyEntity.builder()
.someField("someValue")
.build();
List<MyEntity> entities = repository.findAll(Example.of(entity));
}

我想这与我与AuditableOptional Methods有关,但我不知道如何解决这个问题。
如果我复制没有Auditable的实体类但它是而不是.

修复,我不需要实现Auditable,因为我已经使用@EntityListeners(AuditingEntityListener.class)

最新更新