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:
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
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
Query query = session.createQuery("from Login l where l.id=1")