• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jersey Hibernate Problem

 
Ranch Hand
Posts: 445
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic