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
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
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
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.
Another way of getting the Hibernate Session is to use the delegate method on EntityManager:
Session session = (Session)entityManager.getDelegate();
© 2022 - 2024 — McMap. All rights reserved.