Hi.
For version and snapshot select's, how do you make it work with SPs?
At the moment, the version and snapshot select's show a direct SQL in the logs. I need to get this replaced by SP calls instead. I have tried using, <loader query-ref/> in the mapping file for entity loading, but that doesnt help.
The problem is, in certain cases(save a 1-m, with cascading), Hibernate uses the direct SQL's to check(since the 'id' is assigned) wether the instance is transient/persistent instead of doing it via the SP calls.
The example is a Folder containing folder's.
Here is the output from the logs,
Code:
DEBUG - AbstractEntityPersister:2678: Version select: select ID from FOLDER where ID =?
DEBUG - AbstractEntityPersister:2681: Snapshot select: select folder_.ID, folder_.NAME as NAME0_, folder_.DISPLAY_ORDER as DISPLAY3_0_, folder_.POSTED_DATE as POSTED4_0_, folder_.POSTED_TIME as POSTED5_0_, folder_.CREATED_BY as CREATED6_0_, folder_.START_DATE as START7_0_, folder_.END_DATE as END8_0_, folder_.FOLDER_ID as FOLDER9_0_, folder_.USR_ID as USR10_0_ from FOLDER folder_ where folder_.ID=?
DEBUG - AbstractEntityPersister:2684: Insert 0: { call CREATE_FOLDER(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }
DEBUG - AbstractEntityPersister:2685: Update 0: update FOLDER set NAME=?, DISPLAY_ORDER=?, POSTED_DATE=?, POSTED_TIME=?, CREATED_BY=?, START_DATE=?, END_DATE=?, FOLDER_ID=?, USR_ID=? where ID=?
DEBUG - AbstractEntityPersister:2686: Delete 0: delete from FOLDER where ID=?
And here's a snippet of the mapping file -
Code:
<class
name="example.domain.Folder"
table="FOLDER"
>
<id
name="id"
type="java.lang.Integer"
column="ID"
>
<generator class="assigned" />
</id>
<property
name="name"
type="java.lang.String"
column="NAME"
not-null="true"
unique="true"
length="50"
>
<many-to-one
name="folder"
class="example.domain.Folder"
not-null="true"
>
<meta attribute="use-in-equals">true</meta>
<column name="FOLDER_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to User -->
<many-to-one
name="user"
class="example.domain.User"
not-null="true"
>
<column name="USR_ID" />
</many-to-one>
<set
name="folders"
lazy="true"
inverse="true"
cascade="all,delete-orphan"
>
<key>
<column name="FOLDER_ID" />
</key>
<one-to-many
class="example.domain.Folder"
/>
</set>
<loader query-ref="folder"/>
<sql-insert callable="true" check="none">
{ call CREATE_FOLDER(?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }
</sql-insert>
<sql-query name="folder">
<return alias="f" class="example.domain.Folder" lock-mode="none"/>
{ call FIND_FOLDER(:id) }
</sql-query>
</class>
I have tried, moving the sql-query out of the class.
Thanks.
Amit