Help me to understand SEAM and Hibernate?

落花浮王杯 提交于 2019-12-10 15:37:54

问题


I want to use SEAM Framework with Hibernate but do not want to use EJB. I cannot use EJB.

First question is, can I use EntityManager? or is EntityManager a part of EJB?

How can I get access to use Hibernate in my SEAM component?

Thanks, Philip


回答1:


With Seam, you can use either Hibernate or JPA (EntityManager). It works regardless of EJB. You can use plain POJO if you want.

How can I get access to use Hibernate in my SEAM component ?

Here goes Hibernate settings WEB-INF/components.xml

SessionFactory settings

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

Where app.cfg.xml is placed in the root of the classpath

Session settings

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

TransactionManagement settings

<!--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

/**
  * 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. You can create even your own MVC capabilities if you want. Take a look at JBoss Seam Tuto




回答2:


The Seam website is a good place to start. There's a lot of documentation on the framework.

From the FAQ:

Do I have to use EJB 3 to use Seam?

First, it's important to understand that EJB 3 encompasses session beans, message driven beans, and the Java Persistence API. Seam caters to all three component types, making them easier to use and providing valuable enhancements. But Seam has parallel support for the non-EJB programming model, most notably JavaBeans and native 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. That means once you learn how to use one, you automatically know how to use the other.




回答3:


Another way of getting the Hibernate Session is to use the delegate method on EntityManager:

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


来源:https://stackoverflow.com/questions/3441145/help-me-to-understand-seam-and-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!