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.  [ 3 posts ] 
Author Message
 Post subject: Config files not in Classpath (How can we make it work)
PostPosted: Thu Jun 14, 2007 5:40 pm 
Newbie

Joined: Thu Jun 14, 2007 5:28 pm
Posts: 7
Hi,

We have a requirement of not having config files in the classpath. So i started created a Configuration like:

Configuration cfg = new Configuration()
.addResource("C:/...../ABC.hbm.xml")
.addResource("C:/..../XYZ.hbm.xml")
.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver")
.setProperty("hibernate.connection.url", "xxxxxxxxxx")
.setProperty("hibernate.connection.username", "xxxx")
.setProperty("hibernate.connection.password", "xxxx")
.setProperty("hibernate.connection.pool_size", "1")
.setProperty("show_sql", "true")
.setProperty("hibernate.dialect", "org.hibernate.dialect.OracleDialect")
.setProperty("current_session_context_class", "thread")
.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.EhCacheProvider")
.setProperty("hibernate.cache.use_second_level_cache", "true")
.setProperty("hibernate.cache.use_query_cache", "true");


When i try to execute the test its complaining:

Initial SessionFactory creation failed.org.hibernate.MappingException: Resource: C:/........./ABC.hbm.xml not found
java.lang.ExceptionInInitializerError
at com.util.HibernateUtil.<clinit>(HibernateUtil.java:38)
at com.businessprocess.Test.main(Test.java:32)

Is there a way to get around it with out including your *.hbm.xml files in your classpath.

Your help is really appreciated.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 1:47 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

This is the implementation of addResource(). so you must add your mapping files to project classpath or global classpath.



Code:
public Configuration addResource(String resourceName) throws MappingException {
      log.info( "Reading mappings from resource : " + resourceName );
      ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
      InputStream rsrc = null;
      if (contextClassLoader!=null) {
         rsrc = contextClassLoader.getResourceAsStream( resourceName );
      }
      if ( rsrc == null ) {
         rsrc = Environment.class.getClassLoader().getResourceAsStream( resourceName );
      }
      if ( rsrc == null ) {
         throw new MappingNotFoundException( "resource", resourceName );
      }
      try {
         return addInputStream( rsrc );
      }
      catch (MappingException me) {
         throw new InvalidMappingException( "resource", resourceName, me );
      }
   }


Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 12:52 pm 
Newbie

Joined: Thu Jun 14, 2007 5:28 pm
Posts: 7
I know that it works if we add the config files to classpath. I am looking for some other way to resolve this with out adding the config files to classpath.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.