Are persistence annotations in domain objects a bad practice?

前端 未结 8 932
青春惊慌失措
青春惊慌失措 2021-02-01 15:09

I realize that persistence frameworks such as Morphia and Hibernate rely on annotations on domain objects to do their magic. At some level, it seems to me that this is insertin

8条回答
  •  醉酒成梦
    2021-02-01 15:44

    Are persistence annotations in domain objects a bad practice?

    Yes. With the rise of NoSQL, you can not rely on single persistence strategy.

    For example, today I am persisting my domain objects (let's say using morphia) into MongoDB. What if tomorrow I want to persist domain objects to Neo4j ?

    Or, one might want to persist domain objects to all three kinds of databases like relational (Postgres / MySQL), MongoDB(document store) and Neo4J(graph database) just for evaluating.

    In all these cases, better to have separate persistence strategy rather than just relying on domain objects

    Best Practice : Passing Persistent strategy as a strategy pattern might help. But have to be careful while designing your classes / objects.

提交回复
热议问题