Share on Google+Share on Google+

FaizalArafath
org.hibernate.MappingException: Could not read mappings from resource:
2 Answer(s)      5 years and 9 months 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

Ads

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:
Tutorials   
Java Spring Hibernate Struts Training java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! org.hibernate.validator cannot be resolved error java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion property hibernate.cache.region.factory_class is not given Hibernate example step by step in Eclipse with MySQL How to make Struts Hibernate and Spring Based Login/Registration Application? What is the use of Hibernate Native SQL? What is the use of Hibernate is used? How to integrate Struts and Hibernate in an application? How to create the program in Java for getting the forgotten Password Form? How to write create JPA Many-to-Many Relationship in Java? What is the DAO Layer in any application? What is Spring Struts Hibernate DAO Layer? How to write Example code for CRUD application in hibernate annotation? Where to update the Hibernate tools? Query conversion convert into hql how to convert sql into hql package org.hibernate.util does not exist C3P0 with Hibernate What do you understand by JPA? Hibernate Query Checker Jpa many to many relationship What do you understand by Hibernate in Java? What are criteria Queries in Hibernate? How to use Associations and Joins in Hibernate? Hibernate 4 Example with Eclipse How to learn Hibernate? What is Hibernate Framework? hibernate faq 15/03/14 hibernate 15/03/2014 Hibernate Criteria Wildcard how to add mulitiple projections this is a hibernate question this is a hibernate question this is a hibernate question how to writw connection pool coding Hibernate 4.3 and JPA 2.1 support How to create Hibernate session factory name? Can you provide me Hibernate configuration tutorial? I want to build sessionfactory in hibernate 4. Need help. I want to learn Hibernate tutorial quickly How to create sessionfactory in Hibernate 4.1.1? How to create sessionfactory in Hibernate 4.1? Hibernate 4.3.0.Final get session How to learn hibernate in 24 hours? hibernate 4.3.0 I want to know how can I create sessionfactory in hibernate 4 (latest version) standard serviceregistrybuilder example

Ads

 
Advertisement null

Ads