简体   繁体   English

EJB方法与实体方法,谁应该有哪些方法?

[英]EJB methods vs Entity methods,who should have what methods?

public class EntParent{
 @OneToMany
 List<Ent1> manyEnt1;
}



public class Ent1 {

 Field1
 Field2

 @ManyToOne
 EntParent dad;

 getField1
 setField1

 getField2
 setField2

 getDad
 setDad

}


public class Ent1ManagerEJB{


}

in this scenario who(Ent1 or Ent1ManagerEJB or EntParent) should have methods to perform following 在这种情况下,谁(Ent1或Ent1ManagerEJB或EntParent)应该具有执行以下操作的方法

1) manipulate fields in Ent1 1)在Ent1中操作字段

2) fetch fields of Ent1 with some logic 2)使用一些逻辑来获取Ent1的字段

3) Fetch some other Entity depending on some logic that works on values of fields in Ent1,if EntParent and mappings are absent 3)如果缺少EntParent和映射,则根据对Ent1中的字段值起作用的某些逻辑来获取其他实体

4) Fetch some other Entity depending on some logic that works on values of fields in Ent1,if Ent1 is in @OneToMany mapping with some other Entity eg EntParent contains Ent1 in array 4)如果Ent1在@OneToMany与其他实体的映射中,则根据某些对Ent1中的字段值起作用的逻辑来获取其他实体, eg EntParent contains Ent1 in array

also if possible point to some resource that teaches me about such patterns/problems.. 如果可能的话,还指向一些教给我有关此类模式/问题的资源。

Domain objects represent important concepts in the target domain and so must often be persistent. 域对象代表目标域中的重要概念,因此通常必须是持久性的。 The Java Persistence API (JPA) turns out to be quite flexible for mapping rich domain objects to relational tables. 事实证明,Java Persistence API(JPA)非常灵活,可以将丰富的域对象映射到关系表。 The more complex the logic you need to realize, the more easily object-oriented persistence can be maintained and developed. 您需要实现的逻辑越复杂,就越容易维护和开发面向对象的持久性。

The real issue with complex logic realized with anemic structures are type distinctions in the service layer. 用贫乏的结构实现复杂逻辑的真正问题是服务层中的类型区别。 Massive if-statements might be necessary to differentiate among entity types. 可能需要大量的if语句来区分实体类型。 Every introduction of a new subclass, or even a change in the existing business logic, requires you to find, enhance, and test these type checks. 每次引入新的子类,甚至更改现有的业务逻辑,都需要您查找,增强和测试这些类型检查。

                                                                          Admam Bien

you can take advantage of concept "Domain-driven design" which Adam Bien talked about in his article: 您可以利用Adam Bien在他的文章中谈到的“域驱动设计”概念:

http://www.javaworld.com/javaworld/jw-05-2009/jw-05-domain-driven-design.html?page=2 ? http://www.javaworld.com/javaworld/jw-05-2009/jw-05-domain-driven-design.html?page=2吗?

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

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