相关疑难解决方法(0)

Spring JPA Auditing empty createdBy

我正在使用Spring Data审计功能,并且有一个类似于这样的类:

@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@Table(name="Student")
public class Student {
    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    private Long id;

    @CreatedBy
    private String createdBy;

    @CreatedDate
    private Date createdDate;

    @LastModifiedBy
    private String lastModifiedBy;

    @LastModifiedDate
    private Date lastModifiedDate;
...

现在,我相信我已经配置了审计,因为我可以看到在更新域对象时createdBy,createdDate,lastModifiedBy和lastModifiedDate都获得了正确的值.

但是,我的问题是,当我更新对象时,我将丢失createdBy和createdDate的值.所以,当我第一次创建对象时,我有四个值,但是当我更新它时,createdBy和createdDate都无效!我还使用Hibernate envers来保存域对象的历史记录.

你知道为什么我会这样做吗?当我更新域对象时,为什么createdBy和createdDate为空?

更新:回答@m-deinum的问题:是的,春天数据JPA配置正确 - 其他一切正常 - 我真的不想发布配置,因为你的udnerstand它需要很大的空间.

我的AuditorAwareImpl是这样的

@Component
public class AuditorAwareImpl implements AuditorAware {
    Logger logger = Logger.getLogger(AuditorAwareImpl.class);

    @Autowired
    ProfileService profileService;

    @Override
    public String getCurrentAuditor() {
        return profileService.getMyUsername();
    }
}

最后,这是我的更新控制器实现:

    @Autowired  
    private StudentFormValidator validator;
    @Autowired
    private …

java spring auditing spring-data

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

auditing ×1

java ×1

spring ×1

spring-data ×1