cancel
Showing results for 
Search instead for 
Did you mean: 

Loading files from within the ejb-jar using the classloader

Former Member
0 Kudos

Hello,

i'm trying the following setup;

1/ A J2EE Server Library for hibernate

2/ A Stateless SessionBean using hibernate to create an object in the DB

3/ A Webservice invoking the session bean.

The EAR is already deployed ok and i can call the WebService.

When the SessionBean tries to instantiate the Factory from hibernate, hibernate in term loads a configuration file by the name "/hibernate.cfg.xml" which is contained in the ejb-jar. (I've checked this with jar tvf).

Nevertheless the Factory is unable to find the file.

Is there anything special wrt loading files from inside the ejb-jar in webas ?

regards, Udo

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I did some further analyis on that and come to the following conclusion:

1/ The hibernate.jar gets loaded with a classloader attached to the Lib-Project

2/ The EJBs get loaded using the ApplicationClassloader

Since the files which are not loadable by hibernate reside in the ejb-jar they are not loadable since the classloader from the lib-project does not see the ejb-jar.

Could somebody shed some light on that please ?

regards, udo

0 Kudos

Hello Udo,

Hibernate use the context ClassLoader to resolve resources that are application dependent (fixed in version 1.1). However the hibernate.properties and hibernate.cfg.xml are loaded explicitly with the classloader of the Hibernate library. That makes me think that, this XML document should reside in the library.

If this is unacceptable for you I would suggest that you change the net.sf.hibernate.cfg.Congiuration class of Hibernate to use Thread.currentThread().getContextClassLoader() classloader to load the XML document.

Best Regards,

Dimitar