Joined: Wed Feb 19, 2014 7:40 am Posts: 1
|
employee.jsp -------------------------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body>
<s:form name="frm" action="onetomany" method="post">
<s:textfield name="employee.empid" label="Enter id:"></s:textfield> <s:textfield name="employee.ename" label="Enter name:"></s:textfield>
<s:textfield name="edetail.detailid" label="Enter did:"></s:textfield>
<s:textfield name="edetail.firstname" label="Enter fname::"></s:textfield> <s:textfield name="edetail.lastname" label="Enter lname:"></s:textfield> <s:textfield name="edetail.birthDate" label="Enter bdate:"></s:textfield> <s:textfield name="edetail.cellphone" label="Enter no:"></s:textfield>
<s:submit value="View"></s:submit>
</s:form> </body> </html>
-------------------------------------------- OneToMany.java -------------------------------------------
package action;
import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction;
import pojo.employeedetail; import pojo.employeepojo;
import util.HibernateUtil;
public class OneToMany {
SessionFactory sf = (SessionFactory) HibernateUtil.getSessionFactory(); Session sess = sf.openSession(); Transaction tran=sess.beginTransaction(); employeedetail edetail=new employeedetail(); employeepojo employee=new employeepojo(); public employeedetail getEdetail() { return edetail; }
public void setEdetail(employeedetail edetail) { this.edetail = edetail; }
public employeepojo getEmployee() { return employee; }
public void setEmployee(employeepojo employee) { this.employee = employee; }
public String onetomany() { employee.getEmpid(); employee.getEname(); edetail.getDetailid(); edetail.getFirstname(); edetail.getLastname(); edetail.getBirthDate(); edetail.setEmployee(employee); sess.save(edetail); sess.save(employee); tran.commit(); return "SUCCESS"; }
}
-------------------------------------------- employeepojo.java ---------------------------------------------
package pojo;
import java.util.*;
public class employeepojo { private long empid; private String ename; public Set<employeedetail> edetail; public long getEmpid() { return empid; }
public Set<employeedetail> getEdetail() { return edetail; }
public void setEdetail(Set<employeedetail> edetail) { this.edetail = edetail; }
public void setEmpid(long empid) { this.empid = empid; }
public String getEname() { return ename; }
public void setEname(String ename) { this.ename = ename; } }
---------------------------------------------------- employeedetail.java ----------------------------------------------------
package pojo;
import java.util.Date;
public class employeedetail { private String firstname; private String lastname; private Date birthDate; private int cellphone; private long detailid; private employeepojo employee; public employeepojo getEmployee() { return employee; } public void setEmployee(employeepojo employee) { this.employee = employee; }
public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public Date getBirthDate() { return birthDate; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } public int getCellphone() { return cellphone; } public void setCellphone(int cellphone) { this.cellphone = cellphone; } public long getDetailid() { return detailid; } public void setDetailid(long detailid) { this.detailid = detailid; } }
----------------------------------------- employee.hbm.xml ----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="pojo.employeepojo" table="employee"> <id name="empid" type="java.lang.Long" > <column name="EMPID" /> <generator class="native" /> </id> <property name="ename" type="string"> <column name="EMPNAME"></column> </property> <set name="edetail" table="employeedetail" inverse="true" lazy="true" fetch="select"> <key> <column name="EMPID" not-null="true"></column> </key> <one-to-many class="pojo.employeedetail"/> </set> </class> </hibernate-mapping>
------------------------------------------- employeedetail.hbm.xml -------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="pojo.employeedetail" table="employeedetail"> <id name="detailid" type="java.lang.Long" > <column name="detailID" /> <generator class="native" /> </id> <property name="firstname" type="string"> <column name="FNAME"></column> </property> <property name="lastname" type="string"> <column name="LNAME"></column> </property> <property name="birthDate" type="date"> <column name="BDATE"></column> </property> <property name="cellphone"> <column name="MNO"></column> </property> <many-to-one name="employee" class="pojo.employeepojo" fetch="select"> <column name="EMPID" not-null="true" /> </many-to-one> </class> </hibernate-mapping>
------------------------------------------------ hibernate.cfg.xml ------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/emp1</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">root</property> <property name="hibernate.connection.pool_size">5</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.connection.autocommit">true</property> <property name="hibernate.show_sql">true</property> <property name="hibernate.hbm2ddl.auto">create</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.hbm2ddl.auto">validate</property> <mapping resource="hbm/employee.hbm.xml" /> <mapping resource="hbm/employeedetail.hbm.xml" /> </session-factory> </hibernate-configuration>
--------------------------------------------- I got this error.... please help me to solve the error... ---------------------------------------------------- INFO: table not found: employee Feb 19, 2014 3:15:57 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [default] in context with path [/onetomany] threw exception [Filter execution threw an exception] with root cause org.hibernate.HibernateException: Missing table: employee at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1080) at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294) at util.HibernateUtil.<clinit>(HibernateUtil.java:13) at action.OneToMany.<init>(OneToMany.java:17) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:123) at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:154) at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:143) at com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:113) at com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:275) at com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:365) at com.opensymphony.xwork2.DefaultActionInvocation.access$000(DefaultActionInvocation.java:38) at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(DefaultActionInvocation.java:83) at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455) at com.opensymphony.xwork2.DefaultActionInvocation.<init>(DefaultActionInvocation.java:74) at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189) at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494) at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
|
|