简体   繁体   English

使用spring-data-jdbc进行审核?

[英]Auditing with spring-data-jdbc?

I have seen the response in the previous question ! 我已经在上一个问题中看到了答案! , but it did not solve my problem. ,但并不能解决我的问题。

I traced the code of spring-data-jdbc and found that as long as the BeforeSaveEvent event is customized and a custom ID is set in this event, after the custom event is executed, it continues to trigger the execution of RelationalAuditingEventListener#onApplicationEvent on the entity that has been set to ID. 我跟踪了spring-data-jdbc的代码,发现只要自定义BeforeSaveEvent事件并在此事件中设置了自定义ID,在执行自定义事件后,它就会继续触发在上执行RelationalAuditingEventListener#onApplicationEvent已设置为ID的实体。 The isNew decision is made, ieNew=false. 做出isNew决策,即New = false。

// IsNewAwareAuditingHandler#markAudited // Triggers the markModified method. // IsNewAwareAuditingHandler#markAudited //触发markModified方法。 entity.isNew(object) ? markCreated(object) : markModified(object);

What is the difference between an aggregate root and an entity? 聚合根和实体之间有什么区别? How to design an implementation that can be saved with @CreatedDate and @CreatedBy when using the first save? 使用第一次保存时,如何设计可以用@CreatedDate@CreatedBy保存的实现? @LastModifiedDate and @LastModifyBy ? @LastModifiedDate@LastModifyBy吗?

What you describe sounds like a bug to me. 您所描述的内容对我来说似乎是个错误。 If you set the id in an event listener it should still be handled as a new instance. 如果您在事件侦听器中设置ID,则仍应将其作为新实例进行处理。 Please file an issue at https://jira.spring.io/browse/DATAJDBC 请在https://jira.spring.io/browse/DATAJDBC中提交问题

How to design an implementation that can be saved with @CreatedDate and @CreatedBy when using the first save? 使用第一次保存时,如何设计可以用@CreatedDate和@CreatedBy保存的实现? @LastModifiedDate and @LastModifyBy? @LastModifiedDate和@LastModifyBy?

As a work around you could combine the IsNewAwareAuditingHandler with your event handler for setting the id. 作为解决方法,您可以将IsNewAwareAuditingHandler与事件处理程序结合使用以设置ID。

What is the difference between an aggregate root and an entity? 聚合根和实体之间有什么区别?

An entity is an object that is identified by its id, note that the id might be implicit. 实体是通过其ID标识的对象,请注意,该ID可能是隐式的。 See below. 见下文。

An aggregate is a (typically small) cluster of objects that belong together and get persisted in a single transaction. 聚集是一个(通常很小的)对象簇,它们属于在一起,并且在单个事务中持久存在。 For example a PurchaseOrder and it's LineItem are both entities that belong to the same aggregate. 例如, PurchaseOrder及其LineItem都是属于同一聚合的两个实体。 It is perfectly possible for a single object to be it's own aggregate. 单个对象完全有可能是其自身的集合。

The aggregate root is one entity from an aggregate. 聚合根聚合中的一个实体。 All interactions with the aggregate members should go through the aggregate root. 与聚合成员的所有交互都应通过聚合根。 This allows the aggregate root to control consistency. 这允许聚合根控制一致性。 For example in the example given above PurchaseOrder would be the aggregate root. 例如,在上面给出的示例中, PurchaseOrder将是聚合根。 You therefore would not have a getItems() getter that returns a life collection of the items. 因此,您将没有一个getItems() getter返回项目的生命周期集合。 Instead you would have maybe addItem(productId, amount) and getItems() would return a copy of the items, so changing those won't affect the aggregate. 相反,您可能会有addItem(productId, amount)getItems()返回项目的副本,因此更改这些项目不会影响汇总。

Martin Fowlers definition: https://www.martinfowler.com/bliki/DDD_Aggregate.html 马丁·福尔斯(Martin Fowlers)的定义: https : //www.martinfowler.com/bliki/DDD_Aggregate.html

Great articles about aggregates by Vaughn Vernon: Vaughn Vernon撰写的有关聚合的精彩文章:

https://dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_1.pdf https://dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_1.pdf

https://dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_2.pdf https://dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_2.pdf

https://dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_3.pdf https://dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_3.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM