is not mapped问题,Spring加载jar中配置文件

错误如下:

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配置文件了..

 

你可能感兴趣的:(spring)