Hi iam new to hibernate.
i m doing a toy project in
jsp .At the backend i m using hibernate.
Presently i have created two bean classes user and problemsummary.
user class.
package customer;
public class User {
public
String id;
public String pwd;
public String role;
DBLayer dbObj=new DBLayer();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public boolean isRegister(String uid1,String pwd1)
{
boolean flag=false;
flag= DBLayer.login(uid1,pwd1);
System.out.println(" fff in user isRegistration is called");
return flag;
}
}
another class
package customer;
import org.hsqldb.types.Binary;
public class ProblemsSummary {
public ProblemsSummary()
{
}
private String id;
private String email;
private String sw_type;
private String os;
private Binary problem ;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSw_type() {
return sw_type;
}
public void setSw_type(String sw_type) {
this.sw_type = sw_type;
}
public String getOs() {
return os;
}
public void setOs(String os) {
this.os = os;
}
public Binary getProblem() {
return problem;
}
public void setProblem(Binary problem) {
this.problem = problem;
}
public void setAllValues(String id,String email,String sw,String os,Binary problem )
{
}
}
hibrenate utility class
package customer;
import java.util.Iterator;
import java.util.List;
import javax.transaction.Transaction;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hsqldb.types.Binary;
public class DBLayer {
public static Session getSession()
{
SessionFactory sessionFactory=null;
Session session=null;
try{
sessionFactory=new Configuration().configure().buildSessionFactory();
session=sessionFactory.openSession();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return session;
}
public static synchronized boolean login(String uid ,String pwd)
{
Session session=getSession();
int role=0;
User user=new User();
boolean flag=false;
String sql="from User as user where id='"+uid+"' and pwd='"+pwd+"'";
System.out.println(" fff "+sql);
try{
session.beginTransaction();
List query=session.createQuery(sql).list();
Iterator it=query.iterator();
if(it.hasNext())
{
flag=true;
System.out.println(" fff flaf value in dblayer"+flag);
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
session.getTransaction().commit();
session.close();
return flag;
}
public static synchronized void insertProblem(String id,String email,String sw,String os,Binary problem )
{
Session session=getSession();
ProblemsSummary ps=new ProblemsSummary();
//ps.setId(id);
//ps.setEmail(email);
//ps.setSw_type(sw);
//ps.setOs(os);
//ps.setProblem(problem);
session.save(ps);
session.clear();
}
}
hbm file.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="customer.User" table="user">
<id name="id" column="id" type="string">
<generator class="assigned" />
</id>
<property name="pwd" update="true" insert="true">
<column name="pwd" sql-type="varchar"/>
</property>
</class>
<class name="customer.ProblemSummary" table="problemsummary">
<id name="id" column="id" type="string" >
<generator class="assigned" />
</id>
<property name="email" update="true" insert="true">
<column name="email" sql-type="varchar"/>
</property>
<property name="sw_type" update="true" insert="true">
<column name="sw_type" sql-type="varchar"/>
</property>
<property name="os" update="true" insert="true">
<column name="os" sql-type="varchar"/>
</property>
<property name="problem" update="true" insert="true" type="binary">
<column name="problem" sql-type="blob"/>
</property>
</class>
</hibernate-mapping>
cfg file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/customercare</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="customercare.hbm.xml"/>
</session-factory>
</hibernate-configuration>
when i did not add the second class in hbm file i mean in mapping file it was fine.But after adding the second i m getting errorr.
org.hibernate.InvalidMappingException: Could not parse mapping document from resource customercare.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:602)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1621)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1589)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1568)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1542)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1448)
at customer.DBLayer.getSession(DBLayer.java:21)
at customer.DBLayer.login(DBLayer.java:32)
at customer.User.isRegister(User.java:32)
at org.apache.jsp.jsp.login_jsp._jspService(org.apache.jsp.jsp.login_jsp:89)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.MappingException: class customer.ProblemSummary not found while looking for property: email
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:97)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2193)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2170)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2060)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:381)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:702)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:537)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:599)
... 30 more
Caused by: java.lang.ClassNotFoundException: customer.ProblemSummary
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1332)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:123)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:93)
... 40 more
fff from User as user where id='adi' and pwd='adi123'
java.lang.NullPointerException
at customer.DBLayer.login(DBLayer.java:40)
at customer.User.isRegister(User.java:32)
at org.apache.jsp.jsp.login_jsp._jspService(org.apache.jsp.jsp.login_jsp:89)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)
please help me i am not getting any thing ..I am also trying to get the soln.please help me.
also suggest me that my stucture is fine or not.i need your suggestion.
piyal