【SSH学习】配置ORM元数据后,Tomcat启动异常Exception sending context initialized event to listener instance of class

配置hibernateORM元数据后,爆出异常,百思不得其解。

那天百度了很久:将update注释掉,问题得到解决。

但治标不治本,为什么会出异常,仍然不清楚。

过了两天,框架熟练以后,想再看看这个问题。将注释掉的代码打开,观察异常信息,英文大部分看不懂,但其中主要提到了一个字段cust_industry,难道是这个字段没配好?

再次检查了包含该字段的对象配置XML文件,终于找到元凶:字段配重复了!!!

出问题的那天引入了数据字典,对XML进行了配置,配置了该字段对数据字典的多对一关系,但是没有将之前配置的该字段删掉,导致重启后因为配置了自动建表,会读取映射关系,出现同一个字段两个映射关系,所以报错,这也解释了为什么把auto代码注释掉后就不报错误。

所以:编程必须要细心,且编且仔细。

出了问题不要紧,仔细查看异常信息,不要被大段的异常吓到,里面往往有问题的蛛丝马迹,再去检查代码,往往能够快速解决问题。

配错的XML文件:




    
    	
    		
    	
    	
    	
    	 
    	
    	
    	

    	
    	    	    	
    	
    	
    	
    	
    		
    		
    	
    	
    	
        


异常信息:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: com.aitiman.domain.BaseDict, at table: cst_customer, for columns: [org.hibernate.mapping.Column(cust_industry)]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.MappingException: Could not determine type for: com.aitiman.domain.BaseDict, at table: cst_customer, for columns: [org.hibernate.mapping.Column(cust_industry)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:396)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:369)
at org.hibernate.mapping.Property.isValid(Property.java:225)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:529)
at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:416)
at org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 21 more

你可能感兴趣的:(Java学习)