is not mapped問題,Spring載入jar中設定檔

來源:互聯網
上載者:User

標籤:des   style   io   ar   使用   sp   java   on   檔案   

錯誤如下:

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設定檔了..

 

is not mapped問題,Spring載入jar中設定檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.