JPA + StoredProcedureCall +对象类型IN参数 [英] JPA + StoredProcedureCall + object type IN parameter
问题描述
我正在尝试做一个简单的事情:调用具有对象类型参数的存储过程.
I'm trying to do a simple thing: call stored procedure which have a object type parameter.
这是我在db中拥有的:
This is what I have in db:
create or replace
TYPE TEST_TYPE AS OBJECT
(
test_field varchar(100)
)
和
CREATE OR REPLACE PROCEDURE TEST_PROC
(
PARAM1 IN TEST_TYPE
) AS
BEGIN
END TEST_PROC;
这就是我的Java代码中的内容:
This is what I have in my java code:
@Embeddable
@Struct(name = "TEST_TYPE", fields = {"TEST_FIELD"})
public class TestStruct
{
private String testField;
public String getTestField() {
return testField;
}
public void setTestField(String testField) {
this.testField = testField;
}
}
和
@PostConstruct
public void init()
{
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName("TEST_PROC");
call.addNamedArgument("PARAM1", "PARAM1", Types.STRUCT, "TEST_TYPE", TestStruct.class);
DataReadQuery dataReadQuery = new DataReadQuery(call);
dataReadQuery.addArgument("PARAM1");
TestStruct testStruct = new TestStruct();
List args = new ArrayList();
args.add(testStruct);
Object result = ((EntityManagerImpl)em.getDelegate()).getSession().executeQuery(dataReadQuery,args);
}
这是我在运行时得到的:
this is what I get in runtime:
Internal Exception: java.sql.SQLException: Invalid column type
Error Code: 17004
Call: BEGIN TEST_PROC(PARAM1=>?); END;
bind => [1 parameter bound]
Query: DataReadQuery()
我认为我完全不了解JPA的使用结构的主题
I think I totally don't understand the subject of usage structs with JPA
请帮助我,好人:)
最简单的方法是什么?
推荐答案
请发送完整的代码. 对于使用Spring的调用存储过程,您必须扩展StoredProcedure类.如果您发送完整的代码,我们将为您提供更好的帮助.样本伪代码:
Please send complete your code. For call stored procedures using Spring, you have to extends StoredProcedure class. If you send your complete code, I can help better. sample pseudo code:
class CustomStoredProcedure extends org.springframework.jdbc.object.StoredProcedure
{
CustomStoredProcedure()
{
super([your-data-source], [package-name]);
declareParameter(new SqlParameter([your-struct-name]), Types.STRUCT));
compile();
}
Map<String, Object> execute([your-parameter])
{
return super.execute(inputs);
}
}
为获得更好的帮助,您已经解释了完整的情况.
for better help, you have explain complete situation.
这篇关于JPA + StoredProcedureCall +对象类型IN参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!