Note that there are some explanatory texts on larger screens.

plurals
  1. POjsf - spring - hibernate transaction management
    text
    copied!<p>I'm having trouble figuring the best way to manage transactions in a jsf - spring - hibernate situation. What clued me in was I got the following error message:</p> <pre><code>failed to lazily initialize a collection of role: [class name], no session or session was closed </code></pre> <p>My managed bean called the spring bean which did a call to the dao which uses hibernate and retrieved a collection that had a one-to-many relationship. When I tried to examine the collections I got the error (I know that if I traverse the collection in the dao that will preserve the data but I want to go beyond that).</p> <p>Here is the managed bean code:</p> <pre><code>@Transactional private void loadAppointments() { employees = userService.getEmployees(); } </code></pre> <p>(Note: It is when I try and traverse employees that I get the error.)</p> <p>Here is the spring bean call:</p> <pre><code>public Set&lt;Employee&gt; getEmployees() { return getUserDAO().getEmployees(); } </code></pre> <p>and here is the dao code:</p> <pre><code>List&lt;Employee&gt; employees = getSessionFactory().getCurrentSession().createQuery(" from Employee ").list(); return new HashSet&lt;Employee&gt;(employees); </code></pre> <p>here is part of my applicationContext.xml relating to transactions:</p> <pre><code>&lt;!-- Enable the configuration of transactional behavior based on annotations --&gt; &lt;tx:annotation-driven transaction-manager="txManager"/&gt; &lt;!-- Transaction Manager is defined --&gt; &lt;bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt; &lt;property name="sessionFactory" ref="SessionFactory"/&gt; &lt;/bean&gt; </code></pre> <p>I'm not sure why the @Transactional annotation failed in the Spring bean, could someone explain it to me?</p> <p>One person recommended using JPATransactionManager, but I have no experience with it and I was wondering if anyone else had any recommendations. What's the best / easiest way to control a transaction from my Spring bean? Is there an article or something which lays out the options? This seems to be a fairly dense subject so all help appreciated.</p> <p>Edit: com.dave.model.User com.dave.model.Client com.dave.model.Appointment com.dave.model.Employee com.dave.model.Certificate org.hibernate.dialect.MySQLDialect true </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload