marc henry |
: |
Problem with finder methods
|
|
|
|
|
|
Hello, |
|
|
|
|
|
I have a problem while trying to use finder methods generated by service builder. |
|
|
|
|
|
This is the part of my source code which makes the error : |
|
|
|
|
|
|
|
|
|
|
|
he call to DatabaseUtil.findAll() failed. Well in fact, we enter the method but never leave and the console shows me the following exception : |
|
|
|
|
|
12:15:42,434 ERROR [BasePersistenceImpl:84] Caught unexpected exception org.hibernate.HibernateException |
|
|
|
|
|
any idea ? |
|
|
|
|
|
thanks |
|
|
|
marc henry |
: |
When I try to display exception message (e.getMessage()) , I get :
|
|
|
|
|
|
No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
|
|
|
|
|
|
What could I do ? |
|
|
|
Mazhar Anwar |
: |
Hi, |
|
|
|
|
|
Which version of Liferay you are using? |
|
|
|
|
|
I can't find DatabaseLocalServiceUtil and DatabaseLocalServiceImpl classes in Liferay 5.2.3. |
|
|
|
marc henry |
: |
Hi Mazhar, |
|
|
|
|
|
actually, I generated these classes with service builder (Service Builder plugin on Netbeans) by creating an entity called database. These classes belong to the service layer of the database entity model. |
|
|
|
|
|
I am currently using Liferay 5.2.3 |
|
|
|
Shagul Khajamohideen |
: |
You should call those utils ( like UserUtil.java) from within a localServiceImpl. |
|
|
|
marc henry |
|
I encapsulate the call of Util method in a localService method but unfortunaly it did not solve that issue. |
|
|
|
|
|
My service.xml file : |
|
|
|
|
|
|
|
|
|
marc henry |
|
Hello,
|
|
|
|
|
|
I'm still in trouble with that issue |
|
|
|
|
|
It seems like hibernate cannot open a session. Here is the finder method source code (I have add some System.out.println ()...): |
|
|
|
|
|
|
|
|
|
|
|
this line throws the exception
|
|
|
|
|
|
|
|
|
|
|
|
The thing wich looks really weird is that persisting data with hibernate (like adding an entity) and retrieving data like counting the number of entities in the database work fine. I suppose these operations use hibernate session too . Why does it not work with finder methods ?
|
|
|
|
|
|
Any idea ? |
|
|
|
marc henry |
: |
Ok, i have solved the issue.
|
|
|
|
|
|
I have made some careless mistakes in my source code. |
|
|
|
|
|
1 - Like Shagul said, never call EntryUtil functions directly, but always through a service (EntryLocalServiceImpl.java or EntryServiceImpl.java) even if it's just a facade. |
|
|
|
|
|
2 - If you have to add method to EntryLocalServiceImpl.java or EntryServiceImpl.java don't forget to regenerate services with service builder. |
|
|
|
|
|
3 - Regenerate services will enable you to access methods from service layer through the EntryLocalServiceUtil java class. Always use this class to access the service layer.
|
|
|
|
|
|
nb : Entry is the name of your entity |
|
|
|
|
|
Hope this will help someone else... |
|
|
|
Shagul Khajamohideen |
: |
That's awesome Marc. |
|
|
|
No comments:
Post a Comment