I have stored procedures working when i pass in basic java objects (String, Long, etc.) but i cant seem to pass in my own Entity/Object without getting the following error:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid column type
Error Code: 17004
Call: BEGIN sar_ops.input_rule_no_response(operation_id_in=>?, executing_usr_id_in=>?, rule_obj_in=>?, success_ind_out=>?, error_cur_out=>?); END;
bind => [MO1234ABCD, TEST, Rule [id=99999, last_updated_by=mike], => success_ind_out, => error_cur_out]
Query: ResultSetMappingQuery(name="input_rule_no_response" )
From reading up i thought my code would work (see below). I added the @Struct annotation and gave it the name of the matching oracle object from the Database. I was under the impression from the eclispelink documentation i would only need the @Embeddable and @Struct annotations on my class, but i have also added the @Entity annotation whilst testing a theory but still get the same error. I feel i must be missing some form of configuration for eclipselink to know that the object im passing in is a Java class representation of the Oracle object it expects.
Oracle Object and stored proc definition:
PROCEDURE input_rule_no_response
(
operation_id_in IN operation_id_type
,executing_usr_id_in IN usr_id%TYPE
,rule_obj_in IN rule_obj_type
,success_ind_out OUT uttype.boolean_type
,error_cur_out OUT SYS_REFCURSOR
) IS
...
CREATE OR REPLACE TYPE rule_obj_type AS OBJECT
(
id NUMBER(10),
last_updated_by VARCHAR2(100)
)
My stored procedure is defined as:
@NamedStoredProcedureQuery(
name="input_rule_no_response",
resultClasses={DBError.class, Rule.class},
procedureName="sar_ops.input_rule_no_response",
parameters={
@StoredProcedureParameter(name="operation_id_in", mode=ParameterMode.IN, type=String.class),
@StoredProcedureParameter(name="executing_usr_id_in", mode=ParameterMode.IN, type=String.class),
@StoredProcedureParameter(name="rule_obj_in", mode=ParameterMode.IN, type=Rule.class),
@StoredProcedureParameter(name="success_ind_out", mode=ParameterMode.OUT, type=Character.class),
@StoredProcedureParameter(name="error_cur_out", mode=ParameterMode.REF_CURSOR, type=void.class)
})
And my entity looks like:
@Embeddable
@Entity
@Struct(name="rule_obj_type", fields={"id","last_updated_by"})
public class Rule implements Serializable{
private static final long serialVersionUID = 4768354320081279604L;
@Id
@Column(name="id")
private long id;
@Column(name="last_updated_by")
private String last_updated_by;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getLast_updated_by() {
return last_updated_by;
}
public void setLast_updated_by(String last_updated_by) {
this.last_updated_by = last_updated_by;
}
@Override
public String toString() {
return "Rule [id=" + id + ", last_updated_by="
+ last_updated_by + "]";
}
}
And my execute code:
public boolean inputRuleNoResponse(Rule sar) {
StoredProcedureQuery query = em.createNamedStoredProcedureQuery("input_rule_no_response");
query.setParameter("operation_id_in", "MO1234ABCD");
query.setParameter("executing_usr_id_in", "TEST");
query.setParameter("rule_obj_in", sar);
return query.execute();
}
I am trying to stick to the JPA defined annotations (javax.persistence.*) where possible in the NamedStoredProcedureQuery configuration. Is this possible?