-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Unable to execute class interfacing with hibernate
PostPosted: Wed Apr 05, 2006 1:50 pm 
Newbie

Joined: Thu Aug 11, 2005 12:11 pm
Posts: 8
Hibernate version: 3.0.3

Name and version of the database you are using: Oracle 9.2.0.7


I have an interesting problem on my hands. I've read through the docs and the forums, and understand that what I'm trying to do may not quite be possible in the manner in which I'm seeking, but I figured I'd solicit help and opinions first.

What I'm facing is this: I have Jetspeed portlet application running in a Tomcat web container using Hibernate. This application runs fine, and works as would be expected with hibernate. What I need to do is have a class that is part of the root package strucuture, but separate from the running thread of tomcat. In other words, I need to have the instance of tomcat running my portal application using hibernate, and then run a command line batch of a java program (with a main() method) that will make use of the existing hibernate structures in the portal application.

Currently, the issues I'm having is that when running the java app from the command line, I get an error saying that hibernate cannot find my configuration files (/hibernate.properties and /hibernate.cfg.xml). I'm using the same Hibernate Utility class to generate a session factory that I use within my portal that calls the configuration.configure().buildSessionFactory(); methodology to get a session factory instance in the static portion of the Hibernate utility class. The error subequently gets thrown from the ClassLoader.getSystemResourceAsStream(name) method because it cannot find the hibernate.cfg.xml file.

I know this error is thrown when hibernate cannot locate the resource in question based on the classpath root (my libraries are in WEB-INF/lib and the configuration files are in WEB-INF/classes, which works fine for tomcat). What my question is, is can I "fool" hibernate into using a session factory instance from the tomcat context, or will I have to completely separate out these files I'm writing into thier own "mini" hibernate package where I can put a specialized hibernate.cfg.xml mapping file in the same context as the localized classpath root and compile them separately from my portal application?

It would be much nicer if I could just use the existing Vo and DAO classes I have for the portal application inside the batch java application so I won't have duplicate sources to maintain (as well as a separate application that will be doing basically the same thing as part of the portal).

Thanks in advance for any help and/or insight you can provide.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 5:59 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello,

1)
you could specify a hibernate.cfg.xml in your configuration.configure() method.
2)
you could pack your ORM layer including Hibernate, VO and DAO into a library and reuse this library in your portlet application and in your java application.

3)
Do you really need a separate main file? When it is used for a scheduled task there are probably better solutions available. May be you give some more details what your java application is going to do outside ot the portlets.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.