aspose file tools*
The moose likes Spring and the fly likes Jersey Hibernate Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Jersey Hibernate Problem" Watch "Jersey Hibernate Problem" New topic
Author

Jersey Hibernate Problem

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Hi friends,
I am using jersey with Spring for Web Services and i have a simple POST method where a user can send username and password to validate himself. The method for that is


It always throw NullPointerException at the line where ij.getData() method gets called,(It works fine in other Controllers). But when i remove it and do other processing that doesnt involve Hibernate it'll work. Say, i check these two variables like these



I've heard that jersey isn't compatible with Hibernate. Is that so? If so then what can i do to get it work around? Please help me guys.


Never try to be a hard-worker. Be a smart-worker.
My Blog
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42267
    
  64
I've heard that jersey isn't compatible with Hibernate.

That sounds dubious. When (and how) is the "ij" object initialized to something other than null?


Ping & DNS - my free Android networking tools app
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Ulf Dittmer wrote:
I've heard that jersey isn't compatible with Hibernate.

That sounds dubious. When (and how) is the "ij" object initialized to something other than null?


Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

No matter what, when i try to put DB Code using JPA or with Hibernate it came up with a NullPointerException, otherwise its fine.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42267
    
  64
@AutoWired is a Spring annotation, not a Jersey nor Hibernate annotation, so I'd look for problems in your Spring setup.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Ulf Dittmer wrote:@AutoWired is a Spring annotation, not a Jersey nor Hibernate annotation, so I'd look for problems in your Spring setup.


Now have a look at this code where i autowired the Database (A Service Impl), which is already configured in XML file.



The XML configuration is


Now. let me know what is the problem. Please i am banging my head in a wall for more than one day.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42267
    
  64
Moving to a forum appropriate for Spring questions.
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Ulf Dittmer wrote:Moving to a forum appropriate for Spring questions.


I didn't think i would have anything to do with Spring as other parts of my code , excluding this is working fine. But when i add Hibernate code in Jersey Resource class, it shows this error. The complete stacktrace is
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Even when i change from Jersey to RESTEasy, it won't work. Still showing NullPointerException error. Please someone help me get out from this issue...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42267
    
  64
How have you made sure that Spring is otherwise working fine? I imagine that there is some kind of initialization that needs to happen - does that run, and run successfully? Can you test that other Spring beans -that have nothing to do with Jersey- are being injected OK?
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Ulf Dittmer wrote:How have you made sure that Spring is otherwise working fine? I imagine that there is some kind of initialization that needs to happen - does that run, and run successfully? Can you test that other Spring beans -that have nothing to do with Jersey- are being injected OK?


Yes, rest of them are working fine and when i try to add jersey with Hibernate, it gives me such an error.
sachin burange
Ranch Hand

Joined: Jun 24, 2008
Posts: 41
Try adding getters and setters ij object.
and add AutoWire keyword in top of setter method.


Regards
Sachin
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

sachin burange wrote:Try adding getters and setters ij object.
and add AutoWire keyword in top of setter method.



Why? Does Constructor Injection wont work? Anyway will try that and be back.

UPDATE :

Still Not working. The Code is :

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42267
    
  64

<bean id="dbase" class="com.drasis.database.injection.DatabaseImpl"/>

...

@Autowired
public void setWebServiceImpl (Database dbase){
this.dbase = dbase;
}

Is that how Spring works - the name of a parameter is associated to the ID of a bean? Because otherwise I don't see how this could work. Or is it looking through all beans that implement the "Database" interface?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jersey Hibernate Problem