Hibernate + Stored Procedure

2 respostas
M

Bom dia,

Estou tentando usar hibernate acessando uma procedure no Oracle, ja consultei alguns exemplo e ducumentação do site do hibernate, mas não estou conseguindo.

Procedure:
create or replace procedure SP_GET_NUMBER
(
  seq_cursor out sys_refcursor
)
as

  [...]
  
  open seq_cursor for
  select min(temp_id) as next_number from temp_table 
  where temp_id not in(select frm_number from frm_produtos);
  
end SP_GET_NUMBER;
Mapeamento no hibernate
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>

[...]

	<sql-query name="productFormGDNumber_SP" callable="true">	
        <return-scalar column="next_number" type="long" />
		{? = call SP_GET_NUMBER()}
	</sql-query>
</hibernate-mapping>

Testando a proc no PL/SQL esta funcionando, acredito que deve ser algo no mapeamento.

A proc recebe um "sys_refcursor", eu preciso passar alguma coisa no mapeamento? Se sim o que?

Alguem sabe o que esta errado?

Obrigado,

Rodrigo

2 Respostas

M

Esse foi o erro apresentado no console ao executar o código.

Hibernate: {? = call sp_get_number()}
15:34:52,748  WARN JDBCExceptionReporter:71 - SQL Error: 6550, SQLState: 65000
15:34:52,748 ERROR JDBCExceptionReporter:72 - ORA-06550: line 1, column 13:
PLS-00306: wrong number or types of arguments in call to 'SP_GET_NUMBER'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

dao.PersistanceException: org.hibernate.exception.GenericJDBCException: could not execute query

Deve ser alguem parametro que precisa ser passado no mapeamento mesmo, mas ainda não sei como.

M

Nesse caso uma function resolveu meu problema.

create or replace function FC_GET_NUMBER
  return sys_refcursor is seq_cursor sys_refcursor;
  
  
  open seq_cursor for
  select min(temp_id) as next_number from temp_table
  where temp_id not in(select frm_number from frm_produtos);
  
  return seq_cursor;  
end FC_GET_NUMBER;
Criado 14 de agosto de 2006
Ultima resposta 17 de ago. de 2006
Respostas 2
Participantes 1