开发者

Hibernate dies when JAX libraries added to project

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.


I would start by looking at the code at (ServicetypeDAO.java:100) which is causing the NPE, but it is strange that just including a library could break the application.

If you haven't got a pom.xml then I assume you are using an IDE. The pom.xml is a maven project file which is used to maintain configuration for a project and is used by maven to build/run tests/package/deploy your project.

I would start from first principles and write the POM yourself and use maven to generate the project settings for your IDE. Generating a POM from an IDE will generally result in an overly complex POM, but doing it yourself allows better control of the artefacts required for your project. You could also then take the IDE out of the equation when investigating problems by building/deploy from the command line.

In the POM you can specify what versions of the JAR files your project needs, which in your case are the versions that are not packaged with dependencies.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜