I would like to call a stored procedure from hibernate and store the results in a non-persisted entity. I came across one posting from March 2006 that mentioned that this can be accomplished once Hibernate 3.2 is releases using a result transformer.
Is this true? If so, are there any changes that need to be made to the hibernate-mapping file (an example of my file is below) for this to work? (The reason I ask is because the same posting mentions not using an alias)
an example would be extremely helpful.
StoredProcedures.hbm.xml file;
Code:
<hibernate-mapping>
<sql-query name="test_sp" callable="true">
<return alias="StoredProcedureOutputDTO" class="com.ecm.web.dto.StoredProcedureOutputDTO">
<return-property name="toEmail" column="TOEMAIL"/>
</return>
{? = call TEST_STORED_PROC(myinput) }
</sql-query>
</hibernate-mapping>
stored procedure;
Code:
CREATE OR REPLACE PROCEDURE TEST_SP (
myoutput OUT SYS_REFCURSOR,
myinput IN VARCHAR
)
AS
BEGIN
OPEN myoutput FOR
SELECT TOEMAIL FROM MESSAGE WHERE ID = myinput;
END;
java code;
Code:
return super.getHibernateSession().getNamedQuery("test_sp").setResultTransformer(new AliasToBeanResultTransformer(StoredProcedureOutputDTO.class)).setParameter("myinput", "1").list();