hibernate resource not found when run inside eclipse

Posted on 2006-04-04
Last Modified: 2008-02-20
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]
java.lang.RuntimeException: org.hibernate.MappingException: Resource: /com/knowlist/list/hh/CustomObjAffinity.hbm not found
      at com.knowlist.list.hh.HibernateInit.doInit(
      at com.knowlist.list.hh.HibernateInit.doInit(
Caused by: org.hibernate.MappingException: Resource: /com/knowlist/list/hh/CustomObjAffinity.hbm not found
      at org.hibernate.cfg.Configuration.addResource(
      at org.hibernate.cfg.Configuration.parseMappingElement(
      at org.hibernate.cfg.Configuration.parseSessionFactory(
      at org.hibernate.cfg.Configuration.doConfigure(
      at org.hibernate.cfg.Configuration.doConfigure(
      at org.hibernate.cfg.Configuration.configure(
      at com.knowlist.list.hh.base._BaseRootDAO.initialize(
      at com.knowlist.list.hh.base._BaseRootDAO.initialize(
      at com.knowlist.list.hh.HibernateInit.doInit(
      ... 2 more
Question by:HappyEngineer
    LVL 92

    Accepted Solution

    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

    Author Comment

    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.
    LVL 92

    Assisted Solution

    Whare is CustomObjAffinity.hbm

    Author Comment

    It's at:

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

    LVL 92

    Assisted Solution

    according to that error it should be in:

    LVL 5

    Assisted Solution

    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.
    LVL 30

    Assisted Solution

    You can add it to the Run configuration in Eclipse.

    Author Comment

    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".

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    maxMirror challenge 10 68
    countClumps  challenge 10 68
    JavaScript parse form with colon separated values 2 46
    HashMap Vs TreeMap 12 32
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now