我正在开发一个利用JPA/EclipseLink作为持久层的小型多层应用程序.在我目前的设计中,我有两组对象,POJO和Entity对象,我使用POJO进行常规编程任务,而Entity类用于DB读/写和表映射.
现在有必要让POJO =>实体映射(有问题),然后是第二个Entity ==> DB表映射(JPA注释)?我发现使用Entity类作为我的主java对象更容易,并且在必要时将它们持久化,所有Entity类本质上都是POJO并带有几个JPA注释.
同样在确实需要将事物分开的情况下,POJO =>实体映射的最佳位置是什么,目前我在CRUD方法中这样做,例如
public void addCustomerPOJO(Customer customerPOJO){
//Cteat EntityManager and start a Transaction
//Create Entity class and populate it with values
//from the passed-in regular (non entity) Customer class
//Persiste and close
}
Run Code Online (Sandbox Code Playgroud)
有没有更好或更常见的方法来做到这一点?