I want to override Hibernate's default insert statement by calling an Oracle stored procedure, and at the same time use the "sequence-identity" generator for the ID.
Here's a snippet of my Mapping file...
Code:
<class name="com.test.orm.Process" table="PROCESS">
<id name="processId" type="java.lang.Integer">
<column name="PROCESS_ID" precision="22" scale="0"/>
<generator class="sequence-identity">
<param name="sequence">PROCESS_SEQ</param>
</generator>
</id>
<property name="creationDate" type="timestamp" generated="insert">
<column name="CREATION_DATE" length="11" not-null="true"/>
</property>
.... (other properties)
<sql-insert callable="true" check="none">{call create_process (?, ?, ?, ?, ?, ?)}</sql-insert>
</class>
Currently (with generator class set to 'sequence') hibernate issues 3 calls.
- 1 call to get Sequence.nextval
- 1 call to insert record
- 1 call to get the CreationDate after record inserted
I got rid of 1 of the calls by using "sequence-identity" generator which uses the JDBC driver and calls getGeneratedKeys() -- now I am trying to get rid of the call to get creationDate (I need the date generated by the DB).
So does anyone know how to use Custom SQL for CRUD with stored procedures and sequence-identity generator?