3

我们正在使用 Hiberate + Spring + Maven 来实现一个大型 Web 应用程序。

该应用程序已被划分为多个 Maven 模块的图形,其中一些具有持久性。这些模块在父 Web 应用程序中组合为 Maven 依赖项。并且其中一些模块在其他应用程序中独立使用。

我有以下结构:

core-module 包含核心服务和持久化 api。

social-module 它是一个独立的应用程序,具有自己的实体(例如评论、投票等)服务和持久性 API。

social-integration 这应该是社交模块到核心应用程序的粘合剂,包含关系实体、持久性、服务和控制器。

webapp它只是一个带有 commons spring 配置的 war 容器,并且依赖于所有模块。

我尝试使用 Hibernate 继承来扩展核心类 Project 以添加所需的关系,但我几乎没有问题,我认为这不是正确的实现。

@Entity
@Table(name = "project")
@Inheritance(strategy = InheritanceType.JOINED)
public class Project implements Serializable
{
    .....
}


@Entity
@Table(name = "social_project")
@PrimaryKeyJoinColumn(name = "project_id", referencedColumnName = "id")
public class SocialProject extends Project
{  

  @OneToMany(mappedBy = "project", targetEntity = ProjectComment.class, cascade = CascadeType.ALL)
  protected List<Comment> comments = new ArrayList<Comment>(0);

  @OneToMany(mappedBy = "project", targetEntity = ProjectQuestion.class, cascade = CascadeType.ALL)
  protected List<Question> questions = new ArrayList<Question>(0);

  @OneToMany(mappedBy = "project", targetEntity = ProjectEvent.class, cascade = CascadeType.ALL)
  protected List<Event> events = new ArrayList<Event>(0);


  ......
}

所以...我可以在不更改核心应用程序的情况下在这些模块之间创建干净的关系吗?

4

1 回答 1

0

您可以使用下一个模块更改应用程序的结构:

social-model (or social-schema)
social-dao
social-ws (i.e. web services)
social-runtime (create result jar/war file)

模块之间的依赖关系:

dao depends from model module
ws depends from model and dao modules
runtime depends from all modules

在根 pom 中声明所有模块。在构建期间,Maven 将解决依赖关系并以正确的顺序执行构建:

root,model,dao,ws,runtime

例如 ws 模块将重用来自 dao 模块的 xml Spring 配置文件。只需在 ws 模块的 Spring 配置中使用 import 指令。

于 2014-09-20T21:19:07.833 回答