• 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

Hibernate and web services

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, all,

I've been using these forums for a while now, and they always prove very useful - thank you!

However, I now have an issue I can't find the answer for. Perhaps it's because I don't know where to look.

I'm working with Hibernate. I have my methods working, and all is good.

I want to now create a web service based on these methods - I have not done this before, so am just practicing. I am using JBoss 5 and Axis in order to fit in with a framework.

When I deploy the web service, with a method that simply returns a String, it works fine every time.

However, as soon as I make a connection to a database in the same method, I get the following error:



The web method I'm calling is this:



If I remove the four session lines, it works fine.

The hibernate cfg that I'm using is:



If anyone could help with this error, it would be hugely appreciated. I just don't understand why the database connections are causing an issue...I guess it is something to do with the cfg file, but I do not know what.

Thank you so much in advance for any help.

Robin
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which object is null?
 
Robin Stone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Which object is null?



I had a look into this, and added some outputs after each line of code. The odd thing is that the programme ran the first time, returning the expected response.

But every other time, the outputs in the console window didn't refresh, and that's when I got the response null pointer. It was as if the web service had just stopped working.

I'm using the Web service explorer in Eclipse, but had previously tried with SoapUI too, which did give me the same error.

Is there any reason why after an initial call, it would no longer work?
 
Robin Stone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,

I've isolated the issue to this line (which I never thought would be a problem):



If I don't include this line, I have no issues...but surely this line is necessary!

Is there something I'm missing? Surely I need this line of code...
 
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
Why do you think it's necessary to close the session factory?

But I don't understand those lines of code at all - it seems you're starting a transaction, and then immediately commit it, before anything could have happened in it. What is that supposed to accomplish?
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

On line 6, you are closing the SessionFactory when I think you should be closing the Session instead.

Ulf makes a very good point about doing nothing within your transaction.
 
Robin Stone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Why do you think it's necessary to close the session factory?

But I don't understand those lines of code at all - it seems you're starting a transaction, and then immediately commit it, before anything could have happened in it. What is that supposed to accomplish?



I thought/think it is necessary because when I did a tutorial, that is how they finished the hibernate interaction.

Is it not necessary?

The code doesn't do anything because I'm trying to isolate the issue I'm having. So I stripped out all the code that actually does something, and found that the error was still happening with just those lines of code. As you now saw, I realised it was that one specific line that was causing the problem.
 
Robin Stone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:
On line 6, you are closing the SessionFactory when I think you should be closing the Session instead.

Ulf makes a very good point about doing nothing within your transaction.



Thank you for your suggestion. I will try this and get back - I am having issues with my server at the moment, so can not make any requests. One thing after another!

So what is the difference then? Why is closing the factory causing issues like this? Do you never need to close the factory like I'm doing, and just close the sessions?

As for my code, I had stripped out the meat of the code to isolate the error.
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


that is how they finished the hibernate interaction


Well I cannot think of a reason to close the SessionFactory while your application is running. SessionFactory is quite heavyweight so I would have thought closing and re-opening one would be expensive.

The Javadocs for the class also imply that an application will only have a single instance:
SessionFactory Javadoc
 
Robin Stone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:


that is how they finished the hibernate interaction


Well I cannot think of a reason to close the SessionFactory while your application is running. SessionFactory is quite heavyweight so I would have thought closing and re-opening one would be expensive.

The Javadocs for the class also imply that an application will only have a single instance:
SessionFactory Javadoc



Thank you for that. I realise that closing the factory may have been a bit much, but it looks like the code should still work from what I can tell...

I have tried your suggestion regarding closing the session, and still not joy...
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When using Session, what exception do you get?
 
Robin Stone
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, everyone,

I just thought I'd let you know that I sorted my issue.

In the end, I moved from JBoss to Tomcat, and got far better errors.

Before this, I discovered that commiting the session also closed it, so when I was closing it afterwards, it raised an error when published as a web service; it didn't error at this when I was running it as a regular java application.

This was the major issue I was having. I also found that using a properties file for values wasn't liked by the program being a web service either, but this didn't take long to discover.

So all is good now; thank you for your help, everyone.

Robin
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic