首页 > 解决方案 > org.hibernate.MappingException:无法确定类型:java.util.List for Hierarchy Ref Cursor 函数结果

问题描述

我正在尝试在 DB 中调用一个过程函数,并使用 hibernate 将层次结构答案映射到实体类。我编写的实体假设代表从 ref 游标函数返回的结果结构。该函数的结果有一个属性,它是一个对象列表,并且在该对象内部还有一个属性,它也是另一个对象的列表。在应用程序启动时,我得到了上面标题中所写的 MappingException。我尝试添加注释 @OneToMany 但它不起作用,因为它没有查看数据库中的表。同样,实体代表函数结果,而不是从表中选择。有人知道任何可以防止此异常在应用程序启动中引发的注释吗?

我的实体:

调用过程函数 (rc) 的主要实体:

@NamedNativeQuery(name = "GetDeliveryOptionsRC.runFunction",
        query = "{ ? = call fn_get_delivery_options_rc_dev(:i_account_number,:i_work_order_number,:i_task_id,:i_task_type,:i_content_type_code,:i_sap_operator_code)}", resultClass = GetDeliveryOptionsRC.class,
        hints = {@QueryHint(name = "org.hibernate.callable", value = "true")})
@Entity
@XmlRootElement(name = "GetDeliveryOptionsRC")
public class GetDeliveryOptionsRC implements Serializable {

    @Id
    private Long rownum;

    @Column(name = "ACCOUNT_NUMBER")private Long accountNumber;
    @Column(name = "TASK_TYPE")private Long taskType;
    @Column(name = "CONTENT_TYPE")private String contentType;
    @Column(name = "CONTENT_TYPE_CODE")private Long contentTypeCode;
    @Column(name = "MESSAGE_CODE")private Long messageCode;
    @Column(name = "MESSAGE_ERROR_CODE")private Long messageErrorCode;
    @Column(name = "MESSAGE_ERROR_DESCR")private String messageErrorDescr;
    @Column(name = "DELIVERY_OPTIONS")private List<DeliveryOptionsRC> deliveryOptions;

//getters & setters

}

交付选项实体:

@Entity
@XmlRootElement(name = "DeliveryOptions")
public class DeliveryOptionsRC implements Serializable {

    @Id
    @Column(name = "DELIVERY_TYPE") private String deliveryType;
    @Column(name = "DELIVERY_DESCR") private String deliveryDescr;
    @Column(name = "PRICE") private Double price;
    @Column(name = "EXISTS_FLAG") private String existFlag;
    @Column(name = "IS_VALID") private String isValid;
    @Column(name = "IS_SAP_ORDER") private String isSapOrder;
    @Column(name = "IS_OTHER_ADDRESS") private String isOtherAddress;
    @Column(name = "IS_SCHEDULE_NEEDED") private String isScheduledNeeded;
    @Column(name = "PICKUP_SOURCE") private String pickupSource;
    @OneToMany(targetEntity=ChargeJobs.class, mappedBy="deliveryOptionsRC", fetch=FetchType.EAGER)
    @Column(name = "CHARGE_JOBES") private List<ChargeJobs> chargeJobs;


//getters & setters

}

收费工作实体:

@Entity
@XmlRootElement(name = "ChargeJobs")
public class ChargeJobs implements Serializable {

    @Column(name = "JOB_OFFER_ID") private Long jobOfferId;
    @Id
    @Column(name = "JOB_CODE") private String jobCode;
    @Column(name = "PRICE") private Double price;
    @Column(name = "QUANTITY") private Long quantity;

//getters & setters

}

遥控功能:

CREATE OR REPLACE FUNCTION YES_SIMPLE.fn_get_delivery_options_rc_dev (i_account_number NUMBER,
                                                                                                  i_work_order_number NUMBER ,
                                                                                                  i_task_id NUMBER ,
                                                                                                  i_task_type NUMBER,
                                                                                                  i_content_type_code NUMBER,
                                                                                                  i_sap_operator_code NUMBER
                                                                                                   )
RETURN sys_refcursor
is

out_ref sys_refcursor ;
ret  tr.delivery_options_list_t;
xml sys.xmltype;

begin



     ret:= TR.fn_get_delivery_options    (p_account_number => i_account_number,
                                                   p_work_order_number =>i_work_order_number,
                                                   p_task_id =>i_task_id,
                                                   p_task_type =>i_task_type,
                                                   p_content_type_code =>i_content_type_code,
                                                   p_sap_operator_code => i_sap_operator_code) ;

    open out_ref for
    select ret.Account_number Account_number

                  ,ret.Task_Type Task_Type,
                  ret.content_type content_type,
                  ret.content_type_code content_type_code,
                  ret.message_code message_code,
                  ret.message_error_code message_error_code,
                  ret.message_error_descr message_error_descr

    ,cursor(select DELIVERY_TYPE ,
                  DELIVERY_DESCR ,
                  PRICE  ,
                  EXISTS_FLAG    ,
                  IS_VALID    ,
                  IS_SAP_ORDER    ,
                  IS_OTHER_ADRESS   ,
                  IS_SCHEDULE_NEEDED  ,
                  PICKUP_SOURCE,
                  cursor(select *  from(select * from(select * from table(select ret.delivery_options from dual) ))) charge_jobs 
    from table(select ret.delivery_options from dual) ) delivery_options
    from dual;
   return out_ref;

end;

得到以下结果:

ROWNUM  1
ACCOUNT_NUMBER  13
TASK_TYPE   1
CONTENT_TYPE    OTT
CONTENT_TYPE_CODE   2
MESSAGE_CODE    98
MESSAGE_ERROR_CODE  98
MESSAGE_ERROR_DESCR 
DELIVERY_OPTIONS    <Cursor>


                DELIVERY_TYPE   T
                DELIVERY_DESCR  Tech
                PRICE   0
                EXISTS_FLAG N
                IS_VALID    Y
                IS_SAP_ORDER    N
                IS_OTHER_ADRESS N
                IS_SCHEDULE_NEEDED  Y
                PICKUP_SOURCE   
                CHARGE_JOBS <Cursor>
                                    JOB_OFFER_ID    900310
                                    JOB_CODE    D80
                                    PRICE   0
                                    QUANTITY    1

标签: javaspringhibernateannotationsref-cursor

解决方案


推荐阅读