• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • Last Modified:

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
0
HappyEngineer
Asked:
HappyEngineer
5 Solutions
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now