Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:39:11+00:00 2026-06-18T05:39:11+00:00

I am a Hibernate newbie, attempting a small hibernate example with an embedded Derby

  • 0

I am a Hibernate newbie, attempting a small hibernate example with an embedded Derby database. I am developing in eclipse. I am not using Spring or Maven, I am not setting up a web application, I have no application server. I will no doubt use some of those if the project gets bigger, but right now I’m just trying to get this example to work.

The error I am getting is:

Exception in thread "main" org.hibernate.MappingNotFoundException: resource: javabeat/net/hibernate/EmployeeInfo.hbm.xml not found

and sometimes just:

Exception in thread "main" org.hibernate.MappingNotFoundException: resource: EmployeeInfo.hbm.xml not found

Here is my code; I have marked where the error appears to be coming from – eclipse console shows the exception there and stops running, and it’s the logical place:

package javabeat.net.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class JavaBeatHibernateExample
{
  public static void main(String args[]) throws Exception
  {

    configureDerbyEmbedded();

    Configuration cfg = new Configuration();
    cfg.addClass(javabeat.net.hibernate.EmployeeInfo.class);

    cfg.setProperty("hibernate.connection.driver_class", "org.apache.derby.jdbc.EmbeddedDriver");
    cfg.setProperty("hibernate.connection.password", "password");
    cfg.setProperty("hibernate.connection.url", "jdbc:derby:myEmbeddedDB;create=true");
    cfg.setProperty("hibernate.connection.username", "admin");
    cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.DerbyDialect");
    cfg.setProperty("cache.provider_class", "org.hibernate.cache.NoCacheProvider");

    // Exception almost certainly generated here.
    cfg.addResource("EmployeeInfo.hbm.xml");

    cfg.setProperty("hibernate.current_session_context_class", "thread");
    cfg.setProperty("hibernate.show_sql", "true");
    SessionFactory sessionFactory = cfg.buildSessionFactory();
    Session session = sessionFactory.openSession();
    Transaction transaction = session.beginTransaction();
    transaction.begin();
    EmployeeInfo employeeInfo = new EmployeeInfo();
    employeeInfo.setSno(1);
    employeeInfo.setName("KamalHasan");
    session.save(employeeInfo);
    transaction.commit();
    session.close();
  }

  private static void configureDerbyEmbedded() 
      throws ClassNotFoundException, IllegalAccessException, InstantiationException
  {
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
  }
}

I have the folders in eclipse set up as follows

CarRepair
--src
----javabeat
------net
--------hibernate
----main
------resources
--------javabeat
----------net
------------hibernate

I have an EmployeeInfo.hbm.xml, and I have put it in the following places:
src/javabeat/net/hibernate
main/resources/javabeat/net/hibernate
main/resources

And I always get the above exception. In the first, it just says it cannot find the XML file; in the latter two, it prepends javabeat/net/hibernate in front of the XML filename in the error message.

Is the file supposed to be somewhere else, or is there something else I’m supposed to be doing?

EDIT: Could it be something in the xml file itself, with a misleading error message?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
    <hibernate-mapping>
        <class name="javabeat.net.hibernate.EmployeeInfo" table="Employee_Info">
            <id name="sno" column="sno" type="java.lang.Integer">
            </id>
            <property name="name" column="name" type="java.lang.String"/>
        </class>
    </hibernate-mapping>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:39:13+00:00Added an answer on June 18, 2026 at 5:39 am

    You have quite a special directory layout. Assuming src is a source folder in Eclipse, it will copy all the non-Java files to the classes or bin directory (or whatever directory name you chose for the compiled classes), and the EmployeeInfo.hbm.xml should be directly under src, since you’re telling Hibernate to load it from the root of the classpath:

    cfg.addResource("EmployeeInfo.hbm.xml");
    

    If you place it in main/resources, the code to load it should be

    cfg.addResource("main/resources/EmployeeInfo.hbm.xml");
    

    Why don’t you use your own package hierarchy, and thus use the following directory tree:

    src
      com
        rcook
          myapp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Hibernate and Spring on a small personal project. Well, still a
I am newbie for hibernate,i am using mysql database,with two tables serviceTypeDetails,validateConfig.In serviceTypeDetails,it's having
I am a newbie in hibernate, I am using @javax.persistence.NamedNativeQuery to resolve my stored
I'm a newbie in Database design and in Hibernate too. I started reading the
I started using Hibernate recently and I'm still a newbie, however, the error I'm
Hibernate does not allow me to persist an object that contains an null embedded
I'm a hibernate newbie and I'm not entirely sure how to get the cascade
I am a newbie to Hibernate. I have a school project using MySQL, JDBC,
I am using Hibernate 3 and MySQL5.5. I am a newbie to hibernate and
Im working on developing a webapplication with MySQL Server 5.1, Spring 3.0.5 and Hibernate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.