问题描述
用了两种方式:1、<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop></props></property><propertyname="mappingResources"><list><value>vo/Customer.hbm.xml</value></list></property></bean>
不可行,报错没有找到映射2、<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="configLocation"value="classpath:config/hibernate.cfg.xml"></property><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop></props></property></bean>
hibernate.cfg.xml中:<mappingresource="vo/Customer.hbm.xml"/>可行,可以执行成功搞不懂为什么第一种方式不行,求解
解决方案
解决方案二:
你把mappingResources那一段放到hibernateProperties上面试试。
解决方案三:
试过了还是不行严重:Servlet.service()forservlet[default]incontextwithpath[/MyWork]threwexception[org.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']]withrootcauseorg.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']
解决方案四:
我以前的项目这样写是好的,你参考一下:<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><reflocal="dataSource"/></property><propertyname="mappingResources"><list><value>com/ql/entity/User.hbm.xml</value><value>com/ql/entity/Student.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.show_sql=truehibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.cache.use_second_level_cache=truehibernate.cache.provider_class=org.hibernate.cache.OSCacheProviderhibernate.generate_statistics=truehibernate.connection.release_mode=autohibernate.autoReconnect=true</value></property></bean>
解决方案五:
引用1楼wlwlwlwl015的回复:
你把mappingResources那一段放到hibernateProperties上面试试。
试过了还是不行严重:Servlet.service()forservlet[default]incontextwithpath[/MyWork]threwexception[org.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']]withrootcauseorg.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='asd']
解决方案六:
路径写全,也许是路径不对,没加载到hbm配置文件。
解决方案七:
引用3楼wlwlwlwl015的回复:
我以前的项目这样写是好的,你参考一下:<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><reflocal="dataSource"/></property><propertyname="mappingResources"><list><value>com/ql/entity/User.hbm.xml</value><value>com/ql/entity/Student.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.show_sql=truehibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.cache.use_second_level_cache=truehibernate.cache.provider_class=org.hibernate.cache.OSCacheProviderhibernate.generate_statistics=truehibernate.connection.release_mode=autohibernate.autoReconnect=true</value></property></bean>
多谢回答,但是还是报同样的错以下是我修改后的↓<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="mappingResources"><list><value>vo/Customer.hbm.xml</value></list></property><propertyname="hibernateProperties"><value>hibernate.dialect=org.hibernate.dialect.MySQLDialect</value></property></bean>
解决方案八:
引用5楼wlwlwlwl015的回复:
路径写全,也许是路径不对,没加载到hbm配置文件。
vo已经是src下最外层目录了
解决方案九:
真心求解,虽然用第二种方式可行,但是一直身怀一颗打破砂锅问到底的心,况且刚刚接触SSH,对我以后的学习很有用,希望大家发表各自见解,多谢!
解决方案十:
加上classpath:如下:<propertyname="mappingLocations"><list><value>classpath:vo/Customer.hbm.xml</value><value>classpath:vo/Customer.hbm.xml</value></list></property>
解决方案十一:
<propertyname="mappingLocations"><list><value>classpath:/你的路径/你的路径/*.hbm.xml</value></list></property>
试试通配符方式,匹配你某个文件夹下面的所有以hbm.xml结尾的文件
解决方案十二:
引用9楼gudu1289的回复:
加上classpath:如下:<propertyname="mappingLocations"><list><value>classpath:vo/Customer.hbm.xml</value><value>classpath:vo/Customer.hbm.xml</value></list></property>
也试过了↓,还是报同样错误<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><propertyname="dataSource"><refbean="dataSource"/></property><propertyname="hibernateProperties"><value>hibernate.dialect=org.hibernate.dialect.MySQLDialect</value></property><propertyname="mappingLocations"><list><value>classpath:vo/Customer.hbm.xml</value></list></property></bean>
解决方案十三:
引用10楼applewings2014的回复:
<propertyname="mappingLocations"><list><value>classpath:/你的路径/你的路径/*.hbm.xml</value></list></property>试试通配符方式,匹配你某个文件夹下面的所有以hbm.xml结尾的文件
错误还是一样,报没有映射Customer类严重:Servlet.service()forservlet[default]incontextwithpath[/MyWork]threwexception[org.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='zxc']]withrootcauseorg.hibernate.hql.ast.QuerySyntaxException:Customerisnotmapped[fromCustomerwherecustname='zxc']atorg.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)atorg.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)atorg.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)atorg.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)atorg.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)atorg.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)atorg.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
解决方案十四:
多谢大家提出的可行性分析!如果需要我提供其他配置文件,请随时回帖!多谢!
解决方案十五:
是MyEclipse生成的文件吗?我记得有一个版本它生成映射文件的DTD末尾多了一个空格,所以会出问题!
解决方案:
应该是路径的问题
解决方案:
引用14楼u012171905的回复:
是MyEclipse生成的文件吗?我记得有一个版本它生成映射文件的DTD末尾多了一个空格,所以会出问题!
不是用MyEclipse生成的框架,是我手动敲的。。。
解决方案:
引用15楼u010808697的回复:
应该是路径的问题
目录层次结构很简单的,应该不是路径问题。。。