hibernate resource not found when run inside eclipse

I use Hibernate 3 in Eclipse with Hibernate Synchronizer. When I run code that uses hibernate from the command line (executed using ant) it also works fine. However, if I run that same app in eclipse it fails with the error message at the end of this question.

The problem is that when run from inside eclipse "Thread.currentThread().getContextClassLoader().getResourceAsStream( path )" returns null whereas it succeeds when run outside of eclipse.

What should I do to get this to run inside eclipse?


ERROR[2006-04-04 22:15:27,545] com.knowlist.search.IndexUpdaterQueueManager.main(IndexUpdaterQueueManager.java:39)(IndexUpdaterQueueManager.java39):
java.lang.RuntimeException: org.hibernate.MappingException: Resource: /com/knowlist/list/hh/CustomObjAffinity.hbm not found
      at com.knowlist.list.hh.HibernateInit.doInit(HibernateInit.java:66)
      at com.knowlist.list.hh.HibernateInit.doInit(HibernateInit.java:25)
      at com.knowlist.search.IndexUpdaterQueueManager.main(IndexUpdaterQueueManager.java:29)
Caused by: org.hibernate.MappingException: Resource: /com/knowlist/list/hh/CustomObjAffinity.hbm not found
      at org.hibernate.cfg.Configuration.addResource(Configuration.java:444)
      at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313)
      at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267)
      at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234)
      at org.hibernate.cfg.Configuration.configure(Configuration.java:1162)
      at com.knowlist.list.hh.base._BaseRootDAO.initialize(_BaseRootDAO.java:57)
      at com.knowlist.list.hh.base._BaseRootDAO.initialize(_BaseRootDAO.java:41)
      at com.knowlist.list.hh.HibernateInit.doInit(HibernateInit.java:35)
      ... 2 more
HappyEngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
make sure th resource your are looking for is in the build path
if its in a jar, add that jar
if its in a directory then make sure it is a source directory
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HappyEngineerAuthor Commented:
I found that if I run it using ant from either the command line or from inside eclipse then it executes fine. However, if I execute it directly in eclipse then it fails in the way described above.

I opened up the run configuration in eclipse for this app and set the classpath up to be just like that in the build file and it didn't make any difference.
0
objectsCommented:
Whare is CustomObjAffinity.hbm
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

HappyEngineerAuthor Commented:
It's at:
  J:\prog\workspace\KnowList\WebRoot\WEB-INF\classes

The ant target (which works):
      <target name="indexUpdater">
            <java classname="com.knowlist.search.IndexUpdaterQueueManager">
                  <classpath>
                        <pathelement location="WebRoot/WEB-INF/classes"/>
                        <fileset dir="WebRoot/WEB-INF/lib">
                              <include name="*.jar"/>
                        </fileset>
                  </classpath>
            </java>
      </target>

0
objectsCommented:
according to that error it should be in:

j:\prog\workspace\KnowList\WebRoot\WEB-INF\classes/com/knowlist/list/hh/CustomObjAffinity.hbm
0
mrigankCommented:
When executing directly through Eclipse, set the classpath variables the same as in the ANT script. You will need to specifically add J:\prog\workspace\KnowList\WebRoot\WEB-INF\classes to the classpath to the Eclipse run time environment.
0
Mayank SAssociate Director - Product EngineeringCommented:
You can add it to the Run configuration in Eclipse.
0
HappyEngineerAuthor Commented:
I found that the problem went away when I removed the preceding slash from the beginning of the hbm. So, instead of "/com/knowlist/list/hh/CustomObjAffinity.hbm" I use "com/knowlist/list/hh/CustomObjAffinity.hbm".
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.