Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: SessionFactory configuration problem

  1. #1
    Join Date
    May 2012
    Location
    Brazil
    Posts
    6

    Question SessionFactory configuration problem

    Hello everyone! How are you?

    I'm starting with Spring and got some problems in a project I am doing here. I am using Spring 3.0.6 along with Hibernate 3.2.5 in NetBeans 7.1.

    I decided to use annotation-based configuration to work with Hibernate. I find it easier than programming XML files.
    During deployment, my application connects to the database and creates the tables just as expected. But when I run a test file to test the DAOs and insert a new object in the database, I receive an error message regarding the Session Factory, that prevents my Application Context of being correctly loaded.

    I have sent to pastebin some of the files I think are important. Please click on the links to check their code.


    Just as a reference, the code I pasted as App.java (click here to view) is the one I used to load the application context and instantiate the beans in the XML.

    And, well... after running the App.java file showed above, the following log/error message appeared: click here to view.

    As you can see, the main exception revealed is a bean creation exception due to and unknown method:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in URL [file:C:/Users/Isabela/Documents/MuitoBafao/Code/MuitoBafao/web/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V

    Problem is, I didn't even change the SessionFactory XML code. I copied it from a book I am following and just changed the annotated packages.
    I have also tried using the property "annotatedClasses" and adding all off them from muitobafao.model, one by one, on the list, but had the same result.

    Can anyone please enlighten me? :/

    Thanks!
    Last edited by toffolo; May 9th, 2012 at 08:39 AM. Reason: grammar correction :P

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Judging from the stacktrace you have an incorrect version of the asm libraries. Make sure you have a version to match compatible for the hibernate version you use.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2012
    Location
    Brazil
    Posts
    6

    Default

    Hey Marten, thank you for your answer.

    I thought it was strange as all the libraries were automatically included by NetBeans when I created the project. I haven't changed any of Spring or Hibernate configuration since I installed the IDE (like 45 days ago).

    Anyway ... I redownloaded the whole 3.2.5.ga bundle from Hibernate repository and replaced the org.objectweb.asm library in the project libraries (as that's the one causing the error, right?), but it apparently had no effect. The exception returned stays pretty much the same.

    Just as a reference, I posted the new stacktrace here. You can verify it's not different from the first one.

    As Spring's asm library isn't even listed in the stacktrace, I believe that I don't need to touch it.

    Any other ideas?

    Regards,

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Also make sure you have a proper cglib library... (In general I suggest maven to manage your dependencies).

    I doubt you have classloading issues as this is a command line app.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    May 2012
    Location
    Brazil
    Posts
    6

    Default

    Well, in fact I have cglib-2.1.3 in my libraries. NetBeans also preconfigured it when setting up the project.

    Below you may see a snapshot of all the libraries that are included in the project.
    Libraries.jpg

    I'll attempt to create a new project using Maven + Spring + Hibernate to see if I get any success.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    2.1.3 is pretty old (well actually cglib is pretty old for that matter ). I suggest using the 2.2.2 version and the nodep version (that is/was the version that shipped with the spring framework < 2.5 and is also the last cglib version).

    Also the snapshots get resized so it is pretty much unreadable .
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    May 2012
    Location
    Brazil
    Posts
    6

    Default

    Well, I created a Maven + Spring + Hibernate project in NetBeans and as it didn't have a hibernate.cfg.xml file I include the properties at applicationContext.xml, modifying the SessionFactory and resulting in this XML file.

    The stacktrace is at http://pastebin.com/PfbCHzbD. But you can see in the last lines that my Session Factory is still a problem.

  8. #8
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    No it isn't... It is your configuration... Have you actually READ the stack trace? Judging from the stack trace you point to a package which contains your entities and NOT to the classes, you must list the classes. I strongly suggest a read of the reference guide or at least follow the tutorial you are following.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  9. #9
    Join Date
    May 2012
    Location
    Brazil
    Posts
    6

    Default

    Wow Marten, now you got me confused here.

    The book I'm following (Manning: "Spring in Action", 2nd Ed) uses the annotated model classes as the entities to be used in the XML configuration for sessionFactory (in applicationContext.xml). The exact code provided by the book for this configuration is:
    Code:
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
       <property name="dataSource" ref="dataSource" />
       <property name="annotatedClasses">
          <list>
             <value>com.roadrantz.domain.Rant</value>
             <value>com.roadrantz.domain.Motorist</value>
             <value>com.roadrantz.domain.Vehicle</value>
          </list>
       </property>
       <property name="hibernateProperties">
          <props>
             <prop key="hibernate.dialect">${hibernate.dialect}</prop>
          </props>
       </property>
    </bean>
    As said in the book just after presenting this code:
    "However, instead of configuring one or more mapping files, we must configure AnnotationSessionFactoryBean with one or more classes that are annotated for persistence with Hibernate. Here we’ve listed the domain objects in the RoadRantz application."

    As you can see, I adjusted the code with my own domain objects (POJO classes annotated for Hibernate persistence) and, as I already had a Hibernate configuration file, I replaced the "hibernateProperties" property with a reference to my hibernate.cfg.xml file previously created by NetBeans.

    Once again, my applicationContext.xml using the annotatedClasses property for sessioNFactory configuration is at this link.

    The book configures the Hibernate-backed DAO beans with the code
    Code:
    <bean id="rantDao" class="com.roadrantz.dao.hibernate.HibernateRantDao">
       <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    and, as you can see in my first post, I adjusted my XML accordingly.

    Reading your last comment, I'm afraid I couldn't abstract the difference you see between "entity" and "class". In my point of view, an "entity" is a model class correctly annotated for persistence. Am I missing something here?

  10. #10
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    An entity is a class with the @Entity and other JPA/hibernate mapping annotations without it those are just classes and not entities.

    Your stacktrace clearly indicates that somewhere it thinks the 'muitobafao.model' is a class so it must be configured somewhere either that or the fully qualified name is wrong.

    On a side note you shouldn't be using HibernateTemplate and HibernateDaoSupport (as explained in the reference guide) you should be simply using the SessionFactory directly (HibernateTemplate doesn't add anything anymore since about hibernate 3.0.1).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •