Help me understand SEAM and Hibernate?

I want to use the SEAM Framework with Hibernate, but I do not want to use EJB. I can not use EJB.

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

How can I access using hibernate in my SEAM component?

Thanks Philip

+4
source share
3 answers

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

How can I access using hibernate in my SEAM component?

Here are the settings for Hibernate WEB-INF / components.xml

SessionFactory Settings

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

Where app.cfg.xml is placed at the root of the class path

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 enter a Hibernate session, you can use

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

Remember that Seam works with any MVC infrastructure, although it uses Java Server Faces by default. You can even create your own MVC features if you want. Take a look at JBoss Seam Tuto

+5
source

Seam is a good place to start. There is a lot of documentation on the structure.

From the FAQ:

Do I need to use EJB 3 to use Seam?

First, it’s important to understand that EJB 3 spans the beans session, the message is managed by beans, and the Java API is resilient. The seam serves all three components, making them easier to use and enhance. But the seam is parallel programming support for a non-EJB model, primarily JavaBeans and native Hibernate. Thus, the choice of what to use is up to you. Shov's greatest strength is that it provides a unified architecture for both EJB and non-EJB. This means as soon as you learn how to use it, you automatically know how to use others.

0
source

Another way to get a Hibernate session is to use the delegate method in EntityManager:

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

Source: https://habr.com/ru/post/910152/


All Articles