錯誤如下:
org.hibernate.hql.ast.QuerySyntaxException: Content is not mapped [select new Content (t.id,t.name,t.values,t.systemType,t.type,t.sortnumber) from Content t where 1=1 and t.type = ? and t.systemType = ? order by t.sortnumber desc ]at org.hibernate.hql.ast.util.sessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
場景描述:
Content 在A項目打包的jar文件中,單獨在A項目中使用沒有任何問題.
B項目的Spring配置如下:
<property name="mappingDirectoryLocations"> <list> <value>classpath:/com/mythink/entity/</value> </list> </property>
上網查找原因,在使用spring加載jar包中的配置文件時,不支持通配符,需要一個一個引入.
為驗證,將配置改成如下:
<property name="mappingResources"> <list> <value>com/mythink/entity/common/Content.hbm.xml</value> </list> </property>
重啟訪問,,果然沒問題..但是這樣要一個一個加載配置文件,,超級麻煩..繼續搜索!!
嘿嘿,,還真找到了好方法,更改配置如下:
<!-- 加載jar包中的配置文件,解決is not mapped 問題 --> <property name="mappingJarLocations"> <list> <value>/WEB-INF/lib/xxx.jar</value> </list> </property> <property name="mappingDirectoryLocations"> <list> <value>classpath:/com/mythink/entity/</value> </list> </property>
重啟,,可以正常加載Hibernate配置文件了..
新聞熱點
疑難解答