0

我有这个 hbm 文件只是为了测试/练习如何在 xml 文件中使用命名 sql,但它给了我“命名查询未知:testQuery1”

    public List<Meb_item> namedList() {
    // TODO Auto-generated method stub
    Session session = sessionFactory.getCurrentSession();
    return session.getNamedQuery("testQuery1").list();
}


<hibernate-mapping>
 <class table="SIDEEFFECT.MEB_ITEM"  name="foreign.Meb_item"> 
  <id name="meddev_item_seq">
   <column name="MEDDEV_ITEM_SEQ"/>
  </id>

  <resultset name="testRs">
    <return   class="foreign.Meb_item">
        <return-property name="item_name" column="item_name"></return-property>
    </return>     
  </resultset>

  <sql-query name="testQuery1" callable="true" >
        select * from meb_item     
    <return   class="foreign.Meb_item" >
        <return-property name="item_name" column="item_name"></return-property>
    </return>    
  </sql-query> 
</class> 


这是我的 hibernate.cfg.xml 的一部分

<hibernate-configuration>
    <session-factory>
      <mapping resource="mea_class_no.hbm.xml"/>
      <mapping resource="mea_compay.hbm.xml"/>
      <mapping resource="meb_item.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


我查阅了 JBoss 文档,但找不到问题所在。为什么它说命名查询未知?

4

1 回答 1

0

我想到了。
sql-query 标记似乎对映射文档中的位置很敏感。
我将它从类标签的内部移到了它的外部。
现在它似乎按预期调用。虽然它提示另一个错误。
这是整个映射文件。

    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class table="SIDEEFFECT.MEB_ITEM"  name="foreign.Meb_item"> 
<id name="meddev_item_seq">
 <column name="MEDDEV_ITEM_SEQ"/>
</id>
<property name="machinery_area_code">
 <column name="MACHINERY_AREA_CODE"/>
</property>
<property name="cob_flag_code">
 <column name="COB_FLAG_CODE"/>
</property>
<property name="permit_state_code">
 <column name="PERMIT_STATE_CODE"/>
</property>
<property name="meddev_item_no">
 <column name="MEDDEV_ITEM_NO"/>
</property>
<property name="tax_no">
 <column name="TAX_NO"/>
</property>
<property name="item_name">
 <column name="ITEM_NAME"/>
</property>
<property name="permit_date">
 <column name="PERMIT_DATE"/>
</property>
<property name="manuf_country_code">
 <column name="MANUF_COUNTRY_CODE"/>
</property>
<property name="manuf_name">
 <column name="MANUF_NAME"/>
</property>
<property name="manuf_place">
 <column name="MANUF_PLACE"/>
</property>
<property name="manuf_req_country_code">
 <column name="MANUF_REQ_COUNTRY_CODE"/>
</property>
<property name="manuf_req_name">
 <column name="MANUF_REQ_NAME"/>
</property>
<property name="manuf_req_place">
 <column name="MANUF_REQ_PLACE"/>
</property>
<property name="seller_country_code">
 <column name="SELLER_COUNTRY_CODE"/>
</property>
<property name="seller_name">
 <column name="SELLER_NAME"/>
</property>
<property name="seller_place">
 <column name="SELLER_PLACE"/>
</property>
<property name="manuf_import_entp_name">
 <column name="MANUF_IMPORT_ENTP_NAME"/>
</property>
<property name="manuf_import_zip_no">
 <column name="MANUF_IMPORT_ZIP_NO"/>
</property>
<property name="manuf_import_addr1">
 <column name="MANUF_IMPORT_ADDR1"/>
</property>
<property name="manuf_import_addr2">
 <column name="MANUF_IMPORT_ADDR2"/>
</property>
<property name="cancel_withdw_code">
 <column name="CANCEL_WITHDW_CODE"/>
</property>
<property name="cancel_withdw_date">
 <column name="CANCEL_WITHDW_DATE"/>
</property>
<property name="shape">
 <column name="SHAPE"/>
</property>
<property name="sumr_name">
 <column name="SUMR_NAME"/>
</property>
<property name="size_cnt">
 <column name="SIZE_CNT"/>
</property>
<property name="chart_name">
 <column name="CHART_NAME"/>
</property>
<property name="make_method">
 <column name="MAKE_METHOD"/>
</property>
<property name="use_purpose">
 <column name="USE_PURPOSE"/>
</property>
<property name="use_method">
 <column name="USE_METHOD"/>
</property>
<property name="nb">
 <column name="NB"/>
</property>
<property name="valid_term">
 <column name="VALID_TERM"/>
</property>
<property name="exam_std">
 <column name="EXAM_STD"/>
</property>
<property name="permit_cond">
 <column name="PERMIT_COND"/>
</property>
<property name="remark">
 <column name="REMARK"/>
</property>
<property name="meddev_entp_seq">
 <column name="MEDDEV_ENTP_SEQ"/>
</property>
<property name="mea_class_no">
 <column name="MEA_CLASS_NO"/>
</property>
<property name="grade">
 <column name="GRADE"/>
</property>
<property name="receipt_no">
 <column name="RECEIPT_NO"/>
</property>
<property name="bef_doc_id">
 <column name="BEF_DOC_ID"/>
</property>
<property name="safe_exam_yn">
 <column name="SAFE_EXAM_YN"/>
</property>
<property name="export_dev_yn">
 <column name="EXPORT_DEV_YN"/>
</property>
<property name="same_goods_yn">
 <column name="SAME_GOODS_YN"/>
</property>
<property name="same_item_no">
 <column name="SAME_ITEM_NO"/>
</property>
<property name="storage_method">
 <column name="STORAGE_METHOD"/>
</property>
<property name="material">
 <column name="MATERIAL"/>
</property>
<property name="mention_cont">
 <column name="MENTION_CONT"/>
</property>
<property name="regist_ts">
 <column name="REGIST_TS"/>
</property>
<property name="regist_id">
 <column name="REGIST_ID"/>
</property>
<property name="update_ts">
 <column name="UPDATE_TS"/>
</property>
<property name="update_id">
 <column name="UPDATE_ID"/>
</property>
<property name="serv_target">
 <column name="SERV_TARGET"/>
</property>
<property name="trace_manage_target_yn">
 <column name="TRACE_MANAGE_TARGET_YN"/>
</property>
<property name="reexam_yn">
 <column name="REEXAM_YN"/>
</property>
<property name="reexam_valid_start_date">
 <column name="REEXAM_VALID_START_DATE"/>
</property>
<property name="reexam_valid_end_date">
 <column name="REEXAM_VALID_END_DATE"/>
</property>
<property name="serv_target2">
 <column name="SERV_TARGET2"/>
</property>
<property name="bef_cancel_withdw_code">
 <column name="BEF_CANCEL_WITHDW_CODE"/>
</property>
<property name="issue_org_code">
 <column name="ISSUE_ORG_CODE"/>
</property>
<property name="class_change_yn">
 <column name="CLASS_CHANGE_YN"/>
</property>
<property name="delete_yn">
 <column name="DELETE_YN"/>
</property>
<property name="material_ver">
 <column name="MATERIAL_VER"/>
</property>
<property name="disposable_emed_yn">
 <column name="DISPOSABLE_EMED_YN"/>
</property>
</class> 
<sql-query name="testQuery1"  >
        <return   class="foreign.Meb_item" >
            <return-property name="item_name"><return-column name="item_name"/></return-property>
        </return>
        SELECT ITEM_NAME  FROM MEB_ITEM
    </sql-query> 
 </hibernate-mapping>


我希望它有帮助:)

于 2013-10-28T00:40:11.543 回答