• 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

how can i use hibernate both in standalone and in servlet container?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am having issues testing my hibernate code out of container and i figure this is due to differing configuration btw hibernate use via a web container and in standalone application.. correctly, my hibernate works perfect with tomcat but the same code does not work while testing outside container, what modifications can i make to solve the problem? currently, i have my hibernate.cfg.xml in the webapp/WEB-INF/classes folder, and i have hibernate configured in the server.xml file where i use JNDI to access my jdbc resources.

i guess i need to put my properties file on the classpath for the standalone use.

the code i use to get the Session is in HibernateUtil. It is as follows:

 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I'm not sure about the issue you are facing in particular (are you getting an exception when trying to spin up?), but the application I'm working on now has several pieces, including a webapp and standalone tool. We also use JUnit tests against Hibernate. So we have three different modes where it's used.

True, it took a little work setting it up, but that was mostly due to being new to Hibernate. We are using the JNDI DataSource of Tomcat and set up a similar read-only JNDI tree to make it available in unit tests and the standalone tool via the same code.

One difference is that we use the Spring Framework which provides its own configuration wrapper for Hibernate. But I think you're on the right track. Make sure you can access the config file and it should work from there.
 
Abioye Bankole
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help.

I was getting an exception while I ran the Junit test like: hibernate.cfg.xml not found. meanwhile the file was in the root of src folder and was being copied to target/classes after compilation by eclipse. Hence the file once on the classpath! i found out from this site http://www.hibernate.org/123.html that eclipse does not setup the /target directory properly hence i am considering downloading the mevenide plugin to help me set it up as advised on the site. what do u think?

meanwhile, i have yet to start using an IOC app, but will do soon. for now, i still have some other java tools to figure out. it's a new tool a day in open source java world!!
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Abioye Bankole:
what do u think?

I must confess that ... gasp! ... I haven't switch to Eclipse yet. First, I have way too much work to do right now to lose any productivity to switching time and second my editor has a couple features that I don't think have made it Eclipse yet. However, I do see the latest version has code-folding which I really like, so it may be time soon.
reply
    Bookmark Topic Watch Topic
  • New Topic