Reputation: 21
I'm trying to call a procedure function in DB and to mapped the Hierarchy answer to entity class using hibernate.The entities that I wrote suppose to represent the result structure that is returned from a ref cursor function. The result of the function has a property which is a list of objects and inside that object there is also a property that is also a list of another objects. On application startup I get the MappingException as I wrote in the title above. I tried to add the annotation @OneToMany but it is not working because it is not looking at tables in DB. Again, the entities represent the function result and not select from table tables. Someone has any idea of any annotation that could prevent from this exeception to araise in the application startup?
My Entities:
Main Entity that call to procedure function (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
}
Delivery Options Entity:
@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
}
Charge Jobs Entity:
@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
}
The RC function:
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;
Getting the following result:
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
Upvotes: 2
Views: 117