Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate org.hibernate.MappingException: Could not read mappings from resource:

Have Programming Question? Ask it here!
 
 
 


FaizalArafath
org.hibernate.MappingException: Could not read mappings from resource:
2 Answer(s)      3 years and a month ago
Posted in : Hibernate


mycode: Session session=null;

    try
    {
        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        session =sessionFactory.openSession();
        System.out.println("****************");
        Query query = session.createQuery("from Login where id=1 ");
          // query.setParameter("code", );
          for (Iterator it= query.iterate(); it.hasNext();) 
          {
                   // Contact insurance = (Contact) it.next();
                    Login ob=(Login) it.next();
                    System.out.println("ID: " + ob.getUsername());
                    System.out.println("Name: " +ob.getPassword());

          }
                   session.close();


    }
    catch (Exception exp) {
        // TODO: handle exception

        System.out.println(exp);

    }

login.hbm.xml:

hibernate.cfg.xml:

org.hibernate.dialect.MySQLDialect jdbc:mysql://localhost:3306/studentrecord root root com.mysql.jdbc.Driver

Login.java

package Table_declare;

public class Login {

private int id;
private String username;
private String password;


public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}
public String getUsername() {
    return username;
}
public void setUsername(String username) {
    this.username = username;
}

}

error:

org.hibernate.MappingException: Could not read mappings from resource: hbmxml/login.hbm.xml

please guide me what could be the probs. thanks in advance


Advertisement
View Answers

July 21, 2011 at 3:01 AM


Query query = session.createQuery("from Login where id=1 "); In this change Query query = session.createQuery("from Login l where l.id=2"); or Query query = session.createQuery("select * from Login where id=1");

And also you must see which line code cause or giving error. for that u must e.printStackTrace() must write in catch block. then it prints in console which line u wrote wrong code and ALSO U MUST WRITE ONE login.hbm.xml File inside Table_declare package.and in that mention all instance variables of ur Login class and which database table columns u need to map mention that and write this file name in hbm.cfg.xml file inside tag. Thank u for giving this opportunity to solve ur error is nothing but I am getting knowledge from ur error.



July 21, 2011 at 3:03 AM


Query query = session.createQuery("from Login l where l.id=1")



Related Tutorials/Questions & Answers:
 

 

 

DMCA.com