Please bear with me, I come from .net and am new to the java world.
I have a Spring MVC 3 website that uses hibernate as a DAL. I am trying to add a web service package to the project.
Here’s the problem. As soon as I add the core and jaxb JAX-RS libraries to my solution (the libraries that enable me to add REST-JAX methods to my service project classes), hibernate stops working across the entire project (my website included). Any hibernate call that queries the DB (findbyblah()) throws a NullPointerException. When I remove both of these core libraries, clean, and rebuild, my website starts working again.
I just need to be able to implement a few service methods from my site. Can someone point me in the right direction? Thank you.
UPDATE: Here is the stacktrace:
java.lang.NullPointerException
com.myeclipse.hibernate.ServicetypeDAO.findAll(ServicetypeDAO.java:100)
com.indixium.models.RegistrationModel.<init>(RegistrationModel.java:27)
com.indixium.controllers.RegisterController.get(RegisterController.java:29)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
UPDATE AGAIN:
So I found two articles that look promising:
http://www.hildeberto.com/2008/05/hibernate-and-jersey-conflict-on.html
describes that hibernate and jersey both use asm.jar, but different versions, which is why the conflicting behavior exists. It says, in order to solve this:
To solve this conflict use cglib-nodep.jar instead of cglib.jar and keep ASM version 3.x with Jersey. cglib-nodep.jar includes some ASM classes demanded by cglib.jar, changing the package name to avoid any class conflict.
Unfortunately, I do not know how to “use” a different jar for each library. Any help on this is appreciated.
The second solution I found says to modify the pom.xml file (which I also do not know how to do). I have searched my project and my entire hard drive for a file called pom.xml with no luck. How do I change pom.xml? Here is the link to the second solution:
http://blog.idm.fr/2009/04/jersey-hibernate-conflict.html
If someone can help me implement either of these, it would be much appreciated. Thanks.
Ended up scrapping the JAX-RS approach. I am now using the built in Spring MVC 3 @RequestBody attribute to create a service within my site.
@RequestBody causes a web method to write directly to the output stream, instead of to the routing engine to be parsed and passed to a view dictionary.
I created a controller dedicated to my service and attributed it with @RequestMapping(“/services”). All web methods in this controller are decorated with @RequestBody so that direct data output can be returned.