myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alejandro Valdez <>
Subject MyFaces Orchestra: How to Integrate with Hibernate ?
Date Sat, 06 Jun 2009 15:46:44 GMT
Hello list, I'm trying to integrate MyFaces Orchestra with Hibernate
(and Spring 2.5.6), I have already downloaded the example application
from where an
HibernatePersistentContextFactory is provided, there is also an
example of a DAO that extends the Spring's HibernateDaoSupport class.

I don't like the idea of implement my DAOs extending a Spring class,
so instead I wrote them as the example shown below.

It seems that I'm doing something wrong, because I'm having two kind
of HibernateExceptions at different points of my application, in one
case it's telling that a collection is used in another session, in the
other case that a session is closed.

The application is layered in this way: [conversation score beans] ->
[service layer] -> [dao layer] -> [hibernate]

I can't figure out how HibernatePersistentContextFactory is assigning
the same session to the different DAOs in the dao layer, I think it
isn't happening and that is the cause of the exceptions.

Hope someone can point me in the right direction.


public class HibernateUserDAO implements UserDAO {

	private SessionFactory sessionFactory;
	public HibernateUserDAO() {}
	public Session getSession() {
		return sessionFactory.getCurrentSession();
	public List<UserDto> getAll() {
		Session session = getSession();
		Query query = session.createQuery("FROM UserDto AS user ORDER BY
user.username ASC");
		return (List<UserDto>) query.list();

// other methods...

public class UserServiceImpl implements UserService {
	private UserDAO userDAO;
	@Transactional(readOnly = true)
	public List<UserDto> getAll(){
		return userDAO.getAll();
// other methods...

public class userAdministrationBean {
	UserDto currentUser;
	private UserService userSvc;

	public List<UserDto> getAllUsers() {
		return this.userSvc.getAll();
// other methods...

If you are still reading this, this is the interesting part of the
Spring application-context.xml:


    <!-- 3. the "entity manager" manager -->
    <bean id="persistentContextConversationInterceptor"
      <property name="persistenceContextFactory"

    <!-- 4. conversation - persistence adapter -->
    <bean id="persistentContextFactory"
      <property name="entityManagerFactory" ref="entityManagerFactory"/>

	<bean id="transactionManager"
		<property name="sessionFactory" ref="entityManagerFactory"/>

	<bean id="entityManagerFactory"
		<property name="configLocation">

View raw message