Java – DDD entity and its identifier

There is an entity in my system, which naturally needs an identifier so that it can be uniquely identified Assuming that the database is used to generate identifiers using hibernate and uses native policies, it is obvious that the application code does not have the reliability of assigning identifiers

Solution

This is a broad theme, but there are two possibilities:

>Define your hashcode () and equals (..) according to business keys Contract For example, for the user entity, this will be the user name instead of the automatically generated ID. therefore, you can use the entity in the collection before persistence > use UUID as the primary key and handle the generation yourself See Jeff Atwood's this article and this article to show how to use them with hibernate

(since you mentioned DDD and hibernate, please take a look at my this article.)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>