何时使用实体关系或审核

时间:2018-07-12 23:57:44

标签: java spring spring-boot spring-data-jpa microservices

我正在学习有关在springboot上进行审核的事情。

审核

Spring Data提供了完善的支持,可以透明地跟踪创建或更改实体的人员以及发生该事件的时间点。

@Entity
public class User{
    private Long id;
    private String name;
}

@Entity
@EntityListeners(AuditingListener.class)
public class Post extends{
    private Long id;
    private String tittle;

    @createdby
    private String createdby;//this gonna be a row in the table with the user's `name

}

事实是……与此……

我们需要实体之间的关系吗?, 为什么,何时,如何?

@Entity
private User{
    @Id
    private Long id;
    private String name;

    @OneToMany
    private Collection<Post> post;

    @Entity
    public class Post{
        @Id
        private Long id;
        private String tittle;

        @ManyToOne
        private User user;
    }
}

0 个答案:

没有答案
相关问题