Struts2-Full-Hibernate插件是整合Struts2和Hibernate的标准方式吗? [英] Is Struts2-Full-Hibernate plugin the standard way to integrate Struts2 and Hibernate?

查看:152
本文介绍了Struts2-Full-Hibernate插件是整合Struts2和Hibernate的标准方式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始一个项目,愿意使用Struts2和Hibernate。



我应该使用 struts2-full-hibernate 插件,还是以不同的方式整合它们?

在互联网上搜索困惑我:它是整合它们的标准方式吗?如果没有,这是标准的方式吗?

解决方案

简而言之:


  1. 选择一个前端框架(通常是MVC,然后是 Struts2 JSF2 Spring MVC 等等......你已经选择了Struts2,Java EE 6+堆栈中的标准(不一定是更好,也是最常用的)是JSF2);
  2. 选择一个持久性管理器: JPA 2.0 JSR 317 - Java Persistence API)。 JPA只是注释,你需要一个库来实现它们;可以将 Hibernate 用作JPA实现。 Hibernate不是唯一的JPA提供者,但它是最常用的一个(不一定是最好的),因此是最标准的。通过这种配置,您可以通过从持久层分离表示层(Struts2操作)来构建应用程序的图层, CRUD被执行。 DAO层也不再需要,因为JPA的EntityManager 是dao本身。


  3. 您也可以使用 Hibernate 及其专有注释(或任何其他持久性管理器),并且在这种情况下,使用Struts2, 可以使用(vintage?) Struts2-Full-Hibernate插件。它简化了一些工作,但迫使你使用 OSIV (打开会话视图)(反)模式

  4. b
  5. 在选择了框架和持久性管理器之后,您需要选择一个 DI (依赖注入)管理器。如果您使用的是Java EE 6+,则该标准将使用 CDI JSR 299 - 上下文和依赖注入)。在Java EE 6或怀旧开发者面前,Spring仍然可用。当Java EE缺乏时,它是第一个提供DI / IoC(反转控制)的库。

    具体来说,使用Struts2您可以:







h3>

根据Java EE,使用Struts2(而不是JSF2)的标准配置是:

lockquote


  • Struts2

  • Java EE 6 + (CDI + JPA 2.x + x)

  • Hibernate 4.x

  • Struts2-CDI-plugin



I'm starting a project, willing to use Struts2 and Hibernate.

Should I use the struts2-full-hibernate plugin, or integrate them differently ?

Searching on Internet confused me: is it the standard way to integrate them ? If not, which is the standard way ?

解决方案

In a nutshell:

  1. Choose a framework for the front-end (usually MVC, then Struts2, JSF2, Spring MVC, etc... you've already chosen Struts2. The standard (not necessarily the better nor the most used) in the Java EE 6+ stack is JSF2);
  2. Choose a persistence manager:

    • the standard with Java EE 6+ is JPA 2.0 (JSR 317 - Java Persistence API). JPA are just annotations, you need a library implementing them; Hibernate can be used as JPA implementation. Hibernate is not the only JPA provider, but it is the most used one (not necessarily the best one), and hence the most standard. With this configuration, you can structure the application's layers by separating the presentation layer (Struts2 actions) from the persistence layer, where the CRUD is performed. The DAO layer is also not needed anymore because JPA's EntityManager is the dao itself.

    • You can otherwise use raw Hibernate with its proprietary annotations (or any other persistence manager), and in that case, with Struts2, you can use the (vintage?) Struts2-Full-Hibernate plugin. It simplifies some jobs, but force you to use the OSIV (Open-Session-In-View) (anti)pattern.

  3. After having chosen the framework and the persistence manager, you need to chose a DI (Dependency Injection) manager. If you are using Java EE 6+, the standard is to use CDI (JSR 299 - Contexts and Dependency Injection). Before Java EE 6, or for nostalgic developers, Spring is still available. It's been the first library providing DI / IoC (Inversion of Control) when Java EE was lacking it.

    Specifically, with Struts2 you can:


Conclusion

According to Java EE, the standard configuration with Struts2 (instead of JSF2) is:

  • Struts2
  • Java EE 6+ (CDI + JPA 2.x + EJB 3.x)
  • Hibernate 4.x
  • Struts2-CDI-plugin

这篇关于Struts2-Full-Hibernate插件是整合Struts2和Hibernate的标准方式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆