Tuesday, March 3, 2009

Problem: Could not initialize class HibernateUtil / org.slf4j.LoggerFactory not found

Hi all,

after testing the "upgrade" to the long awaited version 5.2.2 (I can describe the procedure as well if you are interested) I got some nasty problems with hibernate.

For the portlet "EasyComments" hibernate3 worked fine so far - but suddenly I got the following errors:

Could not initialize class HibernateUtil
....
at HibernateUtil.closeSession(session);
Annoyingly there was not more to take from the standard out of tomcat (nor from the logs). Only an additional catch blog in the HibernateUtil class showed the real problem:

org.slf4j.LoggerFactory not found

and later:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"

So it seems that hibernate is using slf4j internally.
Adding the following jars solved the problem:

slf4-api-1.5.6.jar
slf4-simple-1.5.6.jar

The files can be found here:
www.slf4j.org

And finally all worked again.


18 comments:

  1. you saved my life!
    actually there's no need to download further stuff cause the files slf4j-api.jar and slf4j-log4j12.jar are in the liferay-portal libs already, and adding them in the portal-dependency-jars section of liferay-plugin-package.properties is enough. I struggled to make the sample-hibernate-portlet work for 5 days, and it was my first attempt with liferay.. you can imagine the frustration!

    ReplyDelete
  2. Hi Rufus,

    I'm glad id helped. Thanks for the info on the dependencies - that makes things easier! :)

    Good luck with liferay,

    Simon

    P.S:
    If you have further questions - feeld free to ask here

    ReplyDelete
  3. By the way:
    My start with hibernate was pretty frustrating as well. And I'm still not really sure whether it is worth the extra effort (especially for my small database scopes) :)

    I think what bugged me in the beginning was that in my auto-generated hibernate config files there was a attribute missing out of the following:

    <hibernate-mapping default-lazy="false" auto-import="false">

    Anyways - now it's working for the moment.. ;)

    ReplyDelete
  4. It scares me to hear that :) i'm in the process of suggesting the adoption of liferay as the portal of my company, but in my first tests i have the feeling that it's quite unstable yet, last time i had problems to access to the users link in the administrator control panes, it complained about some primary key in the users table... right now it would be a pain to turn back so i'll be testing it further hoping to realize that it's stable enough for our needs

    ReplyDelete
  5. sorry, you were talking about hibernate, not liferay :D

    ReplyDelete
  6. yep.
    you are right - the impression may come up at times. but I think it's the following:

    - liferay has a lot of releases and improvements(that is good!)
    - when a lot of new features are developed, there might be some new bugs as well
    - the (possible) bugs are always fixed very quickly in the following release

    So in general I would say liferay is quite stable. Or recommendable.
    (OK - they could test their new stuff a bit more. Especially migrations paths from older installations)

    btw: one of my next blog entries might be about migration... :)

    ReplyDelete
  7. So you're using liferay at work,if so what version of it ? I recently asked to the italian forum what version is considered more stable for production use, but i got no answer so far... I might replicate it to the general forum, keep up the good job!

    ReplyDelete
  8. Hi Rufus,

    I use it more or less for work - means I am creating public webpages with it.
    That's also the main reason for this blog - not all features of liferay are designed for extranet / internet portals or websites.

    I started with version 4.3.5 now I am on 5.0.1 and I will "migrate" to 5.2.2. within the next days. (I already tested it in my testenvironment)

    I think I would recommend you 5.2.2.
    5.2 has a lot of new features and concepts - and 5.2.2. could be stable enough for your purpose.

    ReplyDelete
  9. Thank you, i'm testing 5.2.2 on tomcat 6.0.18 bundled version and i'm starting to see something useful to show to my boss, hope to see some more interesting articles from you soon :)

    bye

    ReplyDelete
  10. Hi,

    I just started with Liferay 5.2.2 after suggesting it to my manager. However, I did not see any good example that I can use as a base. Is there any good examples out there that work for 5.2.2 version. I started with previous version example but got no luck making it work. Any help is appreciated.

    ReplyDelete
  11. Hey Ikram,

    what kind of examples are you looking for?
    5.2.2. comes with a pre packaged example company which comes up directly as the start page. (7cogs Inc)
    There is an explanation in the readme.html in the liferay folder.

    Or are you looking for real-world websites? There are some linked from the example.

    ReplyDelete
  12. Hi All,

    I am beginner to Liferay portal 5.2.2,can any bady guide me to develope
    jsf portlets with examples?

    thanks in advance.

    ReplyDelete
  13. Hey TVramana, did you already check the beginner guides on liferay.com?
    At "downloads" you will good example JSF portlets for a start.

    If you have more specific questions, let us know :)

    ReplyDelete
  14. Thanks Simon,

    right now my boss wants me to develope webservices in Liferay using Apache Axis,

    I found one webservice example in blogs on Authentication(authenticateByEmailAddress).
    it's working my for me,but when I add new method (getUserByEmailAddress(..)) as webservice,I am facing problems.

    public class MyUserServiceImpl extends MyUserServiceBaseImpl {

    public int authenticateByEmailAddress(long companyId, String emailAddress, String password)
    throws PortalException, SystemException {
    Map headerMap = null;
    Map parameterMap = null;
    int isAuthenticated = UserLocalServiceUtil.authenticateByEmailAddress(companyId, emailAddress, password, headerMap, parameterMap);
    return isAuthenticated;
    }

    public com.liferay.portal.model.UserSoap getUserByEmailAddress(long companyId, String emailAddress)
    throws PortalException, SystemException {
    com.liferay.portal.model.UserSoap user =(com.liferay.portal.model.UserSoap)UserLocalServiceUtil.getUserByEmailAddress(companyId , emailAddress);
    return user;
    }
    }


    following exception I got when I run the client application:

    java.rmi.RemoteException: com.liferay.portal.model.impl.UserImpl

    09:52:05,771 ERROR [MyUserServiceSoap:89] java.lang.ClassCastException: com.life
    ray.portal.model.impl.UserImpl
    java.lang.ClassCastException: com.liferay.portal.model.impl.UserImpl
    at com.ext.portlet.reports.service.impl.MyUserServiceImpl.getUserByEmail
    Address(MyUserServiceImpl.java:23)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflecti

    ....................


    my client application as follows:


    MyUserServiceSoapServiceLocator locator = new MyUserServiceSoapServiceLocator();
    MyUserServiceSoap soap = locator.getPortlet_Reports_MyUserService(_URL(Long.toString(adminId), "Portlet_Reports_MyUserService"));

    UserSoap user = null;
    try {
    user = soap.getUserByEmailAddress(companyid, emailAddress);
    } catch (java.rmi.RemoteException re) {
    System.out.println(re.toString());

    }


    can any body know where I am exactly missing ?.


    thanks in advance.

    ReplyDelete
  15. Hi,

    I'm trying to set up a public blog in order to be visible to everyone given a specific url.
    I'm sure all permissions about role "Guest" are set on "view" but I can't see the blog as unauthenticated user.

    I hope you could help me.

    ReplyDelete
  16. Thanks for ur useful posts....u saved my life actually...

    Sudarsan
    http://javacircuit.blogspot.com

    ReplyDelete
  17. Hi all,

    I am having the same trouble with HibernatUtil, and when searching for solution, I found your post.

    In my case, I have all the needed jar you mentionned, My project is a web site and I am using GWT. The project used to work normally, then I had to reinstall my developpement environment and to import the work, now I am not able to save data using the browser, this only works when testing it locally.

    This is really frustraiting me. Had anyone faced the same problem? any help is welcome!!!

    ReplyDelete
  18. Hi Simon Prinzleve, thanks for your immense contribution!!!

    ReplyDelete

I'm happy about every feedback! :)