如何解决错误激活Bean Validation集成和Hibernate Assertion失败?

时间:2015-03-05 10:16:48

标签: java hibernate struts2

在Web应用程序中尝试使用Struts2和hibernate的示例,其中客户端输入公司详细信息,然后单击AddCompany按钮,这些详细信息将成功添加到Mysql数据库中。我收到两个错误一个是Error activating Bean Validation integration,另一个是an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.ClassNotFoundException: buhingroup.Company from [Module "deployment.OrderPurchase.war:main" from Service Module Loader]

15:15:26,551 INFO  [org.hibernate.cfg.Configuration] (http-localhost/127.0.0.1:8080-1) HHH000043: Configuring from resource: Company.cfg.xml
15:15:26,554 INFO  [org.hibernate.cfg.Configuration] (http-localhost/127.0.0.1:8080-1) HHH000040: Configuration resource: Company.cfg.xml
15:15:26,764 INFO  [org.hibernate.cfg.Configuration] (http-localhost/127.0.0.1:8080-1) HHH000221: Reading mappings from resource: Company.hbm.xml
15:15:27,418 INFO  [org.hibernate.cfg.Configuration] (http-localhost/127.0.0.1:8080-1) HHH000041: Configured SessionFactory: null
15:15:29,545 WARN  [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost/127.0.0.1:8080-1) HHH000402: Using Hibernate built-in connection pool (not for production use!)
15:15:29,554 INFO  [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost/127.0.0.1:8080-1) HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/purchaseorder]
15:15:29,560 INFO  [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost/127.0.0.1:8080-1) HHH000046: Connection properties: {user=root, password=****}
15:15:29,564 INFO  [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost/127.0.0.1:8080-1) HHH000006: Autocommit mode: false
15:15:29,573 INFO  [org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (http-localhost/127.0.0.1:8080-1) HHH000115: Hibernate connection pool size: 20 (min=1)
15:15:30,597 INFO  [org.hibernate.dialect.Dialect] (http-localhost/127.0.0.1:8080-1) HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
15:15:30,932 INFO  [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] (http-localhost/127.0.0.1:8080-1) HHH000399: Using default transaction strategy (direct JDBC transactions)
15:15:30,965 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (http-localhost/127.0.0.1:8080-1) HHH000397: Using ASTQueryTranslatorFactory
15:15:31,215 INFO  [org.hibernate.validator.internal.util.Version] (http-localhost/127.0.0.1:8080-1) HV000001: Hibernate Validator 4.3.1.Final-redhat-1
15:15:31,457 ERROR [org.hibernate.AssertionFailure] (http-localhost/127.0.0.1:8080-1) HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): java.lang.ClassNotFoundException: buhingroup.Company from [Module "deployment.OrderPurchase.war:main" from Service Module Loader]
15:15:43,841 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration

15:15:43,849 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:154)

15:15:43,854 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:312)

15:15:43,859 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)

15:15:43,863 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at buhin.purchaseOrder.CompanyDAO.addCompany(CompanyDAO.java:39)

15:15:43,868 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at buhin.purchaseOrder.Company.execute(Company.java:66)

15:15:43,872 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

15:15:43,876 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

15:15:43,881 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

15:15:43,885 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.reflect.Method.invoke(Method.java:483)

15:15:43,889 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:870)

15:15:43,894 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1293)

15:15:43,899 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.ObjectMethodAccessor.callMethod(ObjectMethodAccessor.java:68)

15:15:43,903 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethodWithDebugInfo(XWorkMethodAccessor.java:117)

15:15:43,908 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:108)

15:15:43,913 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:1369)

15:15:43,917 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.ASTMethod.getValueBody(ASTMethod.java:90)

15:15:43,922 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)

15:15:43,926 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.SimpleNode.getValue(SimpleNode.java:258)

15:15:43,930 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.Ognl.getValue(Ognl.java:494)

15:15:43,934 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at ognl.Ognl.getValue(Ognl.java:458)

15:15:43,939 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.ognl.OgnlUtil$2.execute(OgnlUtil.java:309)

15:15:43,944 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.ognl.OgnlUtil.compileAndExecute(OgnlUtil.java:340)

15:15:43,951 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:307)

15:15:43,956 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:423)

15:15:43,960 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:287)

15:15:43,965 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:250)

15:15:43,970 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.DeprecationInterceptor.intercept(DeprecationInterceptor.java:41)

15:15:43,975 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:43,980 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)

15:15:43,985 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:43,989 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:167)

15:15:43,994 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

15:15:43,999 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,004 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)

15:15:44,009 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)

15:15:44,014 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

15:15:44,019 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,024 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)

15:15:44,030 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,034 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)

15:15:44,039 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

15:15:44,045 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,049 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)

15:15:44,055 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

15:15:44,060 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,064 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)

15:15:44,069 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,077 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)

15:15:44,082 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,088 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.DateTextFieldInterceptor.intercept(DateTextFieldInterceptor.java:125)

15:15:44,094 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,098 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)

15:15:44,103 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,108 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253)

15:15:44,112 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,117 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)

15:15:44,122 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,127 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)

15:15:44,132 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,136 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)

15:15:44,141 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,146 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)

15:15:44,151 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)

15:15:44,156 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,161 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:139)

15:15:44,165 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,170 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)

15:15:44,176 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,180 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)

15:15:44,185 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,190 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)

15:15:44,195 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)

15:15:44,199 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)

15:15:44,204 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)

15:15:44,209 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)

15:15:44,214 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)

15:15:44,219 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)

15:15:44,224 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)

15:15:44,229 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)

15:15:44,234 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)

15:15:44,239 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169)

15:15:44,244 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)

15:15:44,248 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)

15:15:44,253 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)

15:15:44,258 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:344)

15:15:44,262 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)

15:15:44,267 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653)

15:15:44,271 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926)

15:15:44,276 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.Thread.run(Thread.java:745)

15:15:44,281 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) Caused by: org.hibernate.AssertionFailure: Entity class not found

15:15:44,285 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:187)

15:15:44,290 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:159)

15:15:44,294 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.beanvalidation.TypeSafeActivator.activate(TypeSafeActivator.java:111)

15:15:44,299 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

15:15:44,303 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

15:15:44,307 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

15:15:44,312 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.reflect.Method.invoke(Method.java:483)

15:15:44,320 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:148)

15:15:44,328 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   ... 88 more

15:15:44,335 ERROR [stderr] (http-localhost/127.0.0.1:8080-1) Caused by: java.lang.ClassNotFoundException: buhingroup.Company from [Module "deployment.OrderPurchase.war:main" from Service Module Loader]

15:15:44,341 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:213)

15:15:44,348 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:459)

15:15:44,353 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:408)

15:15:44,358 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:389)

15:15:44,363 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:134)

15:15:44,367 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.Class.forName0(Native Method)

15:15:44,371 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at java.lang.Class.forName(Class.java:344)

15:15:44,375 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:171)

15:15:44,380 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyRelationalConstraints(TypeSafeActivator.java:184)

15:15:44,384 ERROR [stderr] (http-localhost/127.0.0.1:8080-1)   ... 95 more

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0

Company.java

package buhin.purchaseOrder;

public class Company {

    public int id;
    public String companyName;
    public String contactPerson;
    public String contactNumber;
    public String eMailId;
    public String location;

    public Company(){

    }

    public int getId(){
        return id;
    }

    public String getCompanyName(){
        return companyName;
    }

    public void setCompanyName(String companyName){
        this.companyName = companyName;
    }

    public String getContactPerson(){
        return contactPerson;
    }

    public void setContactPerson(String contactPerson){
        this.contactPerson = contactPerson;
    }

    public String getContactNumber(){
        return contactNumber;
    }

    public void setContactNumber(String contactNumber){
        this.contactNumber = contactNumber;
    }

    public String getEMailId(){
        return eMailId;
    }

    public void setEMailId(String EMailId){
        this.eMailId = EMailId;
    }

    public String getLocation(){
        return location;
    }

    public void setLocation(String location){
        this.location = location;
    }

    public String toString(Company company){
        return company.id+", "+company.companyName+", "+company.contactPerson+", "+company.contactNumber+", "
                +company.eMailId+", "+company.location;
    }

    public String execute(){
        CompanyDAO.addCompany(this);
        return "SUCCESS";
    }
}

我的CompanyDAO.java是

package buhin.purchaseOrder;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

import buhin.purchaseOrder.Company;
import com.opensymphony.xwork2.ActionSupport;


public class CompanyDAO extends ActionSupport {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    public static SessionFactory sf;
    public static Session session;
    public static Transaction transaction;

    /*public static SessionFactory buildSessionFactory(){
        SessionFactory sf = null;
        return sf;
    }

    public static SessionFactory getSessionFactory(SessionFactory sf){
        if(sf == null) buildSessionFactory();
        return sf;
    }
    */
    public static String addCompany(Company company){

        try{
        Configuration cfg = new Configuration();
        cfg.configure("Company.cfg.xml");
        ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
        sf = cfg.buildSessionFactory(sr);
        session = sf.openSession();
        transaction = session.beginTransaction();
        session.save(company);
        transaction.commit();
        session.close();    
        return "SUCCESS";
        }catch(Exception e){
            e.printStackTrace();
            return "ERROR";
        }
    }

}

0 个答案:

没有答案