Help me to understand SEAM and Hibernate?
Asked Answered
G

3

4

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

Genie answered 9/8, 2010 at 14:41 Comment(0)
K
5

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

Kone answered 9/8, 2010 at 15:54 Comment(1)
@Genie You can use any persistence technology you want. Not just Hibernate or JPAKone
G
0

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.

Gardy answered 9/8, 2010 at 14:48 Comment(0)
P
0

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

Session session = (Session)entityManager.getDelegate();
Papaw answered 13/3, 2012 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.