简体   繁体   English

帮我理解SEAM和Hibernate?

[英]Help me to understand SEAM and Hibernate?

I want to use SEAM Framework with Hibernate but do not want to use EJB. 我想将SEAM Framework与Hibernate一起使用但不想使用EJB。 I cannot use EJB. 我不能使用EJB。

First question is, can I use EntityManager? 第一个问题是,我可以使用EntityManager吗? or is EntityManager a part of EJB? 或者EntityManager是EJB的一部分?

How can I get access to use Hibernate in my SEAM component? 如何在我的SEAM组件中访问Hibernate?

Thanks, Philip 谢谢,菲利普

With Seam, you can use either Hibernate or JPA (EntityManager). 使用Seam,您可以使用Hibernate或JPA(EntityManager)。 It works regardless of EJB. 无论EJB如何都可以。 You can use plain POJO if you want. 如果需要,您可以使用普通POJO。

How can I get access to use Hibernate in my SEAM component ? 如何在我的SEAM组件中访问Hibernate?

Here goes Hibernate settings WEB-INF/components.xml 这里是Hibernate设置WEB-INF / components.xml

SessionFactory settings SessionFactory设置

<persistence:hibernate-session-factory name="sessionFactory" cfg-resource-name="app.cfg.xml"/>

Where app.cfg.xml is placed in the root of the classpath 其中app.cfg.xml放在类路径根目录中

Session settings 会话设置

<persistence:managed-hibernate-session name="session" hibernate-session-factory="#{sessionFactory}" auto-create="true"/>

TransactionManagement settings TransactionManagement设置

<!--It takes care of calling begin and commit in the underlying Transaction API-->
<!--Here a Hibernate Transaction API-->
<tx:hibernate-transaction session="#{session}"/>

To inject your Hibernate Session you can use 要注入您的Hibernate会话,您可以使用

/**
  * Seam lookup Seam enabled components Through its referenced name - session 
  */
private @In Session session;

Keep in mind Seam works with any MVC framework although it uses Java Server Faces by default. 请记住,Seam适用于任何MVC框架,尽管它默认使用Java Server Faces。 You can create even your own MVC capabilities if you want. 如果需要,您甚至可以创建自己的MVC功能。 Take a look at JBoss Seam Tuto 看看JBoss Seam Tuto

The Seam website is a good place to start. Seam网站是一个很好的起点。 There's a lot of documentation on the framework. 关于框架有很多文档。

From the FAQ: 来自FAQ:

Do I have to use EJB 3 to use Seam? 我是否必须使用EJB 3来使用Seam?

First, it's important to understand that EJB 3 encompasses session beans, message driven beans, and the Java Persistence API. 首先,了解EJB 3包含会话bean,消息驱动bean和Java Persistence API非常重要。 Seam caters to all three component types, making them easier to use and providing valuable enhancements. Seam迎合所有三种组件类型,使其更易于使用并提供有价值的增强功能。 But Seam has parallel support for the non-EJB programming model, most notably JavaBeans and native Hibernate. 但Seam同时支持非EJB编程模型,最着名的是JavaBeans和本机Hibernate。 So the choice of what to use is up to you. 所以选择使用什么取决于你。 Seam's greatest strength is that it provides a unified architecture across both the EJB and non-EJB models. Seam最大的优势在于它提供了EJB和非EJB模型的统一架构。 That means once you learn how to use one, you automatically know how to use the other. 这意味着一旦你学会了如何使用它,你就会自动知道如何使用另一个。

获取Hibernate会话的另一种方法是在EntityManager上使用委托方法:

Session session = (Session)entityManager.getDelegate();

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

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