Hql技巧积累之二:hbm.xml文件中经常犯的错
Hibernate使用了*.hbm.xml来进行数据库表与java中的实体类的映射,例如:
<?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="com.liany.mis.perm.orgchart.model.OrgChart" table="ORG_CHART"> <id name="id" type="java.lang.String" column="ID"><generator /> </id> <property name="orgCode" type="java.lang.String" column="ORGCODE" length="50" /> <property name="orgName" type="java.lang.String" column="ORGNAME" length="200" /></class><query name="getAllOrgCharts">from OrgChart c order by c.treeCode</query><query name="checkIsDuplicate"><![CDATA[select count(c.id) from OrgChart cwhere (:id is null or c.id<>:id)and c.orgCode=:orgCode]]></query></hibernate-mapping>
2011-05-15 15:02:13 ERROR ContextLoader:211 - Context initialization failedorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictService' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\liany\mis\common\dict\mis-spring-dict.xml]: Cannot resolve reference to bean 'dictServiceImpl' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictServiceImpl' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\liany\mis\common\dict\mis-spring-dict.xml]: Cannot resolve reference to bean 'dictDAO' while setting bean property 'dictDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictDAO' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\liany\mis\common\dict\mis-spring-dict.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory'defined in file [D:\projects2\mis\war\WEB-INF\classes\com\toone\ipms\ipms-spring-global.xml]: Initialization of bean failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate query mapping checkIsDuplicateorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictServiceImpl' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\liany\mis\common\dict\mis-spring-dict.xml]: Cannot resolve reference to bean'dictDAO' while setting bean property 'dictDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictDAO' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\liany\mis\common\dict\mis-spring-dict.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\toone\ipms\ipms-spring-global.xml]: Initialization of bean failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate query mapping checkIsDuplicateorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dictDAO' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\liany\mis\common\dict\mis-spring-dict.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\toone\ipms\ipms-spring-global.xml]: Initialization of bean failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate query mapping checkIsDuplicateorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\projects2\mis\war\WEB-INF\classes\com\toone\ipms\ipms-spring-global.xml]: Initialization of bean failed; nested exception is org.hibernate.DuplicateMappingException: Duplicate query mapping checkIsDuplicateorg.hibernate.DuplicateMappingException: Duplicate query mapping checkIsDuplicate at org.hibernate.cfg.Mappings.checkQueryExist(Mappings.java:270) at org.hibernate.cfg.Mappings.addQuery(Mappings.java:259) at org.hibernate.cfg.HbmBinder.bindNamedQuery(HbmBinder.java:2596) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:160) at org.hibernate.cfg.Configuration.add(Configuration.java:688) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:523) at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:683) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1099) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:400) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:182) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1054) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:863) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:182) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1054) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:863) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:182) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1054) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:863) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:321) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139) at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934) at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526) at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630) at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314) at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053) at org.apache.catalina.core.StandardHost.start(StandardHost.java:722) at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045) at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443) at org.apache.catalina.core.StandardService.start(StandardService.java:516) at org.apache.catalina.core.StandardServer.start(StandardServer.java:710) at org.apache.catalina.startup.Catalina.start(Catalina.java:583) 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 org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)2011-5-15 15:02:13 org.apache.catalina.core.StandardContext start严重: Error listenerStart2011-5-15 15:02:13 org.apache.catalina.core.StandardContext start