problem description
recently in the study of the hibernate framework, the test code did not have the exception of java.lang.reflect.InvocationTargetException, normal operation.
however, under the web project, a java.lang.reflect.InvocationTargetException exception occurred
the environmental background of the problems and what methods you have tried
Myeclipse10,tomcat7,hibernate5
at first, I was looking for a solution on Baidu. Someone misguided https://blog.csdn.net/u010652. by guiding the jar package. But obviously, my problem is not the location of the jar package
related codes
/ / Please paste the code text below (do not replace the code with pictures)
/ / CustomerDao
public class CustomerDao implements ICustomerDao {
@Override
public boolean addCustomer(Customer cust) {
boolean flag=false;
Session s = Dbutil.getSession();
Transaction ts = s.beginTransaction();
s.save(s);
ts.commit();
s.close();
flag=true;
return flag;
}
}
/ / entity class Customer
public class Customer extends Father {
private static final long serialVersionUID = 1L;
private Long cust_id;
private String cust_name;
private Long cust_user_id;
private Long cust_create_id;
private String cust_source;
private String cust_industry;
private String cust_level;
private String cust_linkman;
private String cust_phone;
private String cust_mobile;
private String cust_info;
public Customer() {}
public Customer(Long cust_id, String cust_name, Long cust_user_id,
Long cust_create_id, String cust_source, String cust_industry,
String cust_level, String cust_linkman, String cust_phone,
String cust_mobile, String cust_info) {
this.cust_id = cust_id;
this.cust_name = cust_name;
this.cust_user_id = cust_user_id;
this.cust_create_id = cust_create_id;
this.cust_source = cust_source;
this.cust_industry = cust_industry;
this.cust_level = cust_level;
this.cust_linkman = cust_linkman;
this.cust_phone = cust_phone;
this.cust_mobile = cust_mobile;
this.cust_info = cust_info;
}
public Long getCust_id() {
return cust_id;
}
public void setCust_id(Long cust_id) {
this.cust_id = cust_id;
}
public String getCust_name() {
return cust_name;
}
public void setCust_name(String cust_name) {
this.cust_name = cust_name;
}
public Long getCust_user_id() {
return cust_user_id;
}
public void setCust_user_id(Long cust_user_id) {
this.cust_user_id = cust_user_id;
}
public Long getCust_create_id() {
return cust_create_id;
}
public void setCust_create_id(Long cust_create_id) {
this.cust_create_id = cust_create_id;
}
public String getCust_source() {
return cust_source;
}
public void setCust_source(String cust_source) {
this.cust_source = cust_source;
}
public String getCust_industry() {
return cust_industry;
}
public void setCust_industry(String cust_industry) {
this.cust_industry = cust_industry;
}
public String getCust_level() {
return cust_level;
}
public void setCust_level(String cust_level) {
this.cust_level = cust_level;
}
public String getCust_linkman() {
return cust_linkman;
}
public void setCust_linkman(String cust_linkman) {
this.cust_linkman = cust_linkman;
}
public String getCust_phone() {
return cust_phone;
}
public void setCust_phone(String cust_phone) {
this.cust_phone = cust_phone;
}
public String getCust_mobile() {
return cust_mobile;
}
public void setCust_mobile(String cust_mobile) {
this.cust_mobile = cust_mobile;
}
public String getCust_info() {
return cust_info;
}
public void setCust_info(String cust_info) {
this.cust_info = cust_info;
}
@Override
public String toString() {
return "Customer [cust_id=" + cust_id + ", cust_name=" + cust_name
+ ", cust_user_id=" + cust_user_id + ", cust_create_id="
+ cust_create_id + ", cust_source=" + cust_source
+ ", cust_industry=" + cust_industry + ", cust_level="
+ cust_level + ", cust_linkman=" + cust_linkman
+ ", cust_phone=" + cust_phone + ", cust_mobile=" + cust_mobile
+ ", cust_info=" + cust_info + "]";
}
}
/ / customerServlet method
public class customerServlet extends BaseServlet {
private static final long serialVersionUID = 1L;
public void addsubmit (HttpServletRequest request, HttpServletResponse response) {
String param1 = request.getParameter("cust_name");
String param2 = request.getParameter("cust_level");
Customer cust=new Customer();
cust.setCust_name(param1);
cust.setCust_level(param2);
new CustomerDao().addCustomer(cust);
}
}
what result do you expect? What is the error message actually seen?
the code runs normally (the above code is fine in the test example)
error message:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at Servlet.BaseServlet.service(BaseServlet.java:20)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ExceptionInInitializerError
at Dao.impl.CustomerDao.addCustomer(CustomerDao.java:14)
at Servlet.customerServlet.addsubmit(customerServlet.java:22)
... 23 more
Caused by: org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found: Entity/customer.hbn.xml: origin (Entity/customer.hbn.xml)
at org.hibernate.boot.spi.XmlMappingBinderAccess.bind(XmlMappingBinderAccess.java:56)
at org.hibernate.boot.MetadataSources.addResource(MetadataSources.java:274)
at org.hibernate.boot.cfgxml.spi.MappingReference.apply(MappingReference.java:70)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:413)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at Dao.Dbutil.<clinit>(Dbutil.java:12)
... 25 more