Forums de discussion

Caused by: org.hibernate.HibernateException: No Hibernate Session bound to

thumbnail
Ashish kumar sinha, modifié il y a 15 années.

Caused by: org.hibernate.HibernateException: No Hibernate Session bound to

New Member Publications: 14 Date d'inscription: 07/01/09 Publications récentes
Hi Guys,
I am new to LIferay and using version 5.1.


I need to run a custom query. Below are the steps I followed.

1. Added my custom query in 'announcements.xml' file under 'sr/custom-sql/announcements.xml'

2. Added finder method name in 'AnnouncementFinder' interface.

<method>
findByAgroup(int group) throw SystemException;
</method>

3. Gave implementation in "AnnouncementFinderImpl' which extends <BasePersistenceImpl>

<implementation>

findByAgroup(int group) throws SystemException {

//call of openSession method is the problem
openSession();
}

</implementation>

4. OPENSESSION() method throws exception

"Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

Does any one have idea why openSession() method is throwing hibernate exception?

Is there any solution to solve this issue??
thumbnail
Alex Wallace, modifié il y a 15 années.

RE: Caused by: org.hibernate.HibernateException: No Hibernate Session bound

Liferay Master Publications: 640 Date d'inscription: 05/11/07 Publications récentes
You need to execute your method inside of a *LocalServiceImpl or *ServiceImpl method, those have a hibernate session...

Hope this helps.
thumbnail
Ashish kumar sinha, modifié il y a 15 années.

RE: Caused by: org.hibernate.HibernateException: No Hibernate Session bound

New Member Publications: 14 Date d'inscription: 07/01/09 Publications récentes
Thanks Alex for your reply

1. Using *LocalServiceImp", how to get "session" object, as session object is required to run my custom query?

SQLQuery query = session.createSQLQuery ( myCustomQueryStrng );

2. HibernateUtil.openSession() method is no more in liferay 5.1.

3. Tried to use "AnnouncmentsEntryFinderImpl" given by LIferay to add my query, which threw hibernate exception.



Below are the steps tried to execute -

1. Added blank entity "ExtFinder" without any coloum and run "build-service".

2 . Added execute method in "ExtFinderLocalServiceImp".

But the question is how to get session object here in my ExtFinderLocalServiceImp as it extends ExtFinderLocalServiceBaseImpl.


Please suggest
thumbnail
Alex Wallace, modifié il y a 15 années.

Re: [Liferay Forums][3. Development] RE: Caused by: org.hibernate.Hibernate

Liferay Master Publications: 640 Date d'inscription: 05/11/07 Publications récentes
Ashish kumar sinha from liferay.com wrote:
> Thanks Alex for your reply
>
> 1. Using *LocalServiceImp", how to get "*session*" object, as session
> object is required to run my custom query?
>
Yes...

Create a service of your own, even if it is just a Facade and don't need
to create a db table... Then create a wrapper method to your actual
finder's method...

By calling your finder's method from the *ServiceImpl file, you will get
the session... From your portlets or other parts of the portal you would
call it via:

YourLocalServiceUtil.yourMethod()

Hope that helps.
thumbnail
Ashish kumar sinha, modifié il y a 15 années.

RE: Re: [Liferay Forums][3. Development] RE: Caused by: org.hibernate.Hiber

New Member Publications: 14 Date d'inscription: 07/01/09 Publications récentes
Wow!! Done - got "session" object

Thank you so much Alex for your quick and precise reply emoticon

Below are the steps to get "session" object, so we can run our custom query.

1. Add findXX() method into "YFinderImpl", you need to add same into <interface>"YFinderService" and <util> "YFinderUtil".

2. Create <entity name="ExtFinder" ....></entity> without any coloum.

3. run build-service, will generates ExtFinderLocalServiceImpl, ExtFinderLocalServiceUtil and other classes.

4. Add wrapper method into ExtFinderLocalServiceImpl.

wrapper method should call *FinderUtil.findXX().. just like below

public class ExtFinderLocalServiceImpl ... {
public List<X> wrapper(int id) throws XX{
return YFinderUtil.findXX ( id );
}
}


Done -------- This way you liferay push session here to execute your custom query.



Once again many thankx to Alex
thumbnail
Alex Wallace, modifié il y a 15 années.

RE: Re: [Liferay Forums][3. Development] RE: Caused by: org.hibernate.Hiber

Liferay Master Publications: 640 Date d'inscription: 05/11/07 Publications récentes
You are welcome! emoticon
Martin Petrovsky, modifié il y a 13 années.

RE: Re: [Liferay Forums][3. Development] RE: Caused by: org.hibernate.Hiber

New Member Publications: 2 Date d'inscription: 24/08/10 Publications récentes
You will notice that "service-builder" generates an interface for your implementation (in 5.2.3 at least). That interface is marked up with something like ...


import com.liferay.portal.kernel.annotation.Isolation;
import com.liferay.portal.kernel.annotation.Transactional;

@Transactional(isolation = Isolation.PORTAL, rollbackFor =  {PortalException.class, SystemException.class})
public interface UserSearchService extends UserFinder {


which setups up a transaction context & hibernate sessions.