This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The thing is I want to make a simple SPring MVC application that uses Hibernate to map a class over a table and insert/delete CRUD system on that table.
How do I do that ?:
- first I cannot find a tutorial/example that actually works (with the jars of Spring 3/ Hibernate 4/ Eclipse Indigo/MySQL). Anyone know a new tutorial(tutorial for these versions of jars) ?
- wasted a ton of time trying to make some examples run by adding jars on them only to get compatibility issues. Anyone knows a working project ?
- how do I connect the web.xml with the hibernate.cfg.xml ? Is there a free tutorial explaining this ?
- what happen with the returnSessionFactory.java class ? In all SPringMVC + Hibernate tutorials I see this class does not exist , it is embedded in the web.xml or some other .xml file as the SessionFactory bean. Anywhere I can get more information on this (like how Spring links the beans) ?
Thank you for your answers and for your time , please help me if you can.
Unfortunately, to fully explain it all would take a lot of time. So I am going to just do the basics.
1) Do you understand Spring and Spring configuration?
If you do then this will make sense.
Basically to integrate Hibernate with Spring, and that also means a Spring MVC application. Is to configure and start Hibernate via Spring configuration.
To do that you basically create a <bean> where you use Spring's LocalSessionFactoryBean or AnnotationSessionFactoryBean class as the class="" part of the <bean> tag.
Then you just set that bean's properties. In this case, you don't need a hibernate.cfg.xml file anymore, all that configuration is now in that <bean> tag. That is typically how you integrate Hibernate in Spring. It is all documented in the Core Spring documentation. Under the data sections, right after jdbc. (FYI, you can also set a property of those FactoryBean classes to point to the hibernate.cfg.xml file)
Look at the section 13.3 Hibernate here for more info on the FactoryBean configuration.
Ok , I wrote a simple SpringMVC+Hiberante example, wrote the xml to configure the MVC stuff and hibernate and sessionFactory , I added all the jars for it to run , but when I run it the following error appears:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.updateAccessedAttributes()