pihuu 0 Newbie Poster

I encountered a problem when trying to use hibernate to save details onto my database.

> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
> > SLF4J: Defaulting to no-operation (NOP) logger implementation
> > SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
> > Exception in thread "main" org.hibernate.HibernateException: /hibernate.cfg.xml not found
> >     at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
> >     at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2176)
> >     at org.hibernate.cfg.Configuration.configure(Configuration.java:2157)
> >     at org.hibernate.cfg.Configuration.configure(Configuration.java:2137)
> >     at hybernate1.Test.main(Test.java:33)
> 

C:\Users\Bartosz\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1

Class containing main class:

public static void main(String[] args){

        Hybernate1 user = new Hybernate1();
        user.setUserId(1);
        user.setUserName("Bartosz");
        //save object in database using HIBERNATE API

        //1 step- create a session factory - hibernate.cfg.xml - only one per application
        //session from the session factory - retrieve itd
        //session to save model

        //build session factory
       SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
       Session session = sessionFactory.openSession();
       //begin transaction
       session.beginTransaction();
       session.save(user);
       session.getTransaction().commit();
    }

My second class

@Entity
public class Hybernate1 {


    //Variables
//primary key for the object    
@Id    
    private int userId;
    private String userName;

    //Setters and Getters
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

}

The file hibernate.cfg.xml is in the same folder as the two classes.

Do you have any idea what is cauisng the problem?

Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.