I updated the blog entry by the single working PL.
http://www.jroller.com/HazemBlog/entry/implementing_hibernate_open_session_per
*Here it is:*
public class OSPVFPL implements PhaseListener {
public void beforePhase(PhaseEvent event) {
SessionFactory sessionFactory =
HibernateSessionFactory.getInstance();
sessionFactory.getCurrentSession().beginTransaction();
}
public void afterPhase(PhaseEvent event) {
SessionFactory sessionFactory =
HibernateSessionFactory.getInstance();
try {
sessionFactory.getCurrentSession().getTransaction().commit();
} catch (Throwable ex) {
// very bad error here, occured...
if (sessionFactory.getCurrentSession().
getTransaction().isActive()) {
sessionFactory.getCurrentSession().
getTransaction().rollback();
}
}
}
public PhaseId getPhaseId() {
return PhaseId.INVOKE_APPLICATION;
}
}
On Thu, Sep 11, 2008 at 12:34 PM, Hazem Saleh <[EMAIL PROTECTED]> wrote:
> I will provide the new proper way soon to the wiki as well + a working
> sample to make everything clear.
>
>
> On Thu, Sep 11, 2008 at 12:27 PM, Hazem Saleh <[EMAIL PROTECTED]> wrote:
>
>> Just a small note, I think you do not need two transactions as the SELECT
>> operations do not transactions.
>>
>> If you implemented a single INVOKE_APPLICATION PL that will be enough.
>>
>> Thank you.
>>
>>
>> On Thu, Sep 11, 2008 at 11:48 AM, Ayub Khan <[EMAIL PROTECTED]> wrote:
>>
>>> Thank you Simon !!! I will try implementing the transactions around the
>>> listeners and check if it resolves the issue.
>>> Regards
>>> Ayub
>>>
>>>
>>> On Thu, Sep 11, 2008 at 9:35 PM, Simon Kitching <[EMAIL PROTECTED]>wrote:
>>>
>>>> Ayub Khan schrieb:
>>>>
>>>>> Hi,
>>>>>
>>>>> I have impleted the phaseListener using the idea presented on
>>>>> http://www.jroller.com/HazemBlog/entry/implementing_hibernate_open_session_per
>>>>>
>>>>> I am getting "org.hibernate.HibernateException: createQuery is not
>>>>> valid without active transaction" error message.
>>>>> Below is the code of phase listeners:
>>>>>
>>>>> public class RestoreViewPhaseListener implements PhaseListener {
>>>>>
>>>>> public void afterPhase(PhaseEvent event) {
>>>>> }
>>>>>
>>>>> public void beforePhase(PhaseEvent event) {
>>>>> SessionFactory sessionFactory =
>>>>> HibernateUtil.getSessionFactory();
>>>>> sessionFactory.getCurrentSession().beginTransaction();
>>>>>
>>>>>
>>>>> }
>>>>>
>>>>> public PhaseId getPhaseId() {
>>>>> return PhaseId.RESTORE_VIEW;
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> Please let me where to open and close session and transaction.
>>>>>
>>>>
>>>> Firstly, as Hazem's blog says, you need two PhaseListeners.
>>>>
>>>> But the blog article looks incomplete anyway. As the comment by wolveman
>>>> points out, there probably needs to be a transaction around the render
>>>> phase
>>>> as well as one around the postback phase. Shouldn't be too hard to
>>>> implement..
>>>>
>>>> Regards,
>>>> Simon
>>>>
>>>>
>>>
>>>
>>> --
>>> -- "Two roads diverged in a wood
>>> And I took the one less traveled by
>>> And that has made all the difference.
>>>
>>> Robert Frost....."
>>>
>>
>>
>>
>> --
>> Hazem Ahmed Saleh Ahmed
>>
>> Web blog: http://www.jroller.com/page/HazemBlog
>>
>> [Web 2.0] GMaps Integration with JSF + Apache Tomahawk + JBoss a4j:
>> http://code.google.com/p/gmaps4jsf/
>>
>
>
>
> --
> Hazem Ahmed Saleh Ahmed
>
> Web blog: http://www.jroller.com/page/HazemBlog
>
> [Web 2.0] GMaps Integration with JSF + Apache Tomahawk + JBoss a4j:
> http://code.google.com/p/gmaps4jsf/
>
--
Hazem Ahmed Saleh Ahmed
Web blog: http://www.jroller.com/page/HazemBlog
[Web 2.0] GMaps Integration with JSF + Apache Tomahawk + JBoss a4j:
http://code.google.com/p/gmaps4jsf/