• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jersey Hibernate Problem

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to a forum appropriate for Spring questions.
 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding getters and setters ij object.
and add AutoWire keyword in top of setter method.

 
Rajkumar balakrishnan
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic