We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

hibernate resource not found when run inside eclipse

HappyEngineer
on
Medium Priority
687 Views
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] 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
Comment
Watch Question

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Whare is CustomObjAffinity.hbm

Author

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>

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
according to that error it should be in:

j:\prog\workspace\KnowList\WebRoot\WEB-INF\classes/com/knowlist/list/hh/CustomObjAffinity.hbm
Commented:
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.
Mayank SPrincipal Technologist
CERTIFIED EXPERT
Commented:
You can add it to the Run configuration in Eclipse.

Author

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".
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.