aspose file tools*
The moose likes Object Relational Mapping and the fly likes how can i use hibernate both in standalone and in servlet container? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "how can i use hibernate both in standalone and in servlet container?" Watch "how can i use hibernate both in standalone and in servlet container?" New topic
Author

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

Abioye Bankole
Greenhorn

Joined: Apr 20, 2004
Posts: 8
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:

David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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

Joined: Apr 20, 2004
Posts: 8
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

Joined: Aug 07, 2003
Posts: 1646
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.
 
 
subject: how can i use hibernate both in standalone and in servlet container?