Note that there are some explanatory texts on larger screens.

plurals
  1. POhibernate.cfg.xml not found - exception in java
    primarykey
    data
    text
    <p>I am creating a simple application to learn Hibernate. I am using NetBeans IDE and I created a class in <strong>com.hibernate</strong> package. The class is defined as:</p> <pre><code>package com.hibernate; import com.mahesh.entity.UserDetails; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.classic.Session; public class hibr { public static void main(String[] args) { UserDetails user = new UserDetails(); user.setUserID(1); user.setUserName("Mahesh"); SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); session.beginTransaction(); session.save(user); session.getTransaction().commit(); } } </code></pre> <p>I have defined UserDetails class as:</p> <pre><code>package com.mahesh.entity; import javax.persistence.Entity; import javax.persistence.Id; /** * * @author Mahesh */ @Entity public class UserDetails { @Id private int userID; private String userName; public void setUserID(int userID) { this.userID = userID; } public void setUserName(String userName) { this.userName = userName; } public int getUserID() { return userID; } public String getUserName() { return userName; } } </code></pre> <p><strong>I have defined a hibernate.cfg.xml file which is in src folder(default package)</strong></p> <p><strong>This is the error generated by NetBeans IDE.</strong></p> <blockquote> <p>Feb 27, 2012 8:51:35 AM org.hibernate.cfg.Configuration configure INFO: configuring from resource: /hibernate.cfg.xml Feb 27, 2012 8:51:35 AM org.hibernate.cfg.Configuration getConfigurationInputStream INFO: Configuration resource: /hibernate.cfg.xml Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147) at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405) at org.hibernate.cfg.Configuration.configure(Configuration.java:1427) at org.hibernate.cfg.Configuration.configure(Configuration.java:1414) at com.hibernate.hibr.main(hibr.java:18) Java Result: 1</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload