These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: <sql-insert/update> fields out of order in generated s
PostPosted: Thu Jun 28, 2007 12:26 pm 
Beginner
Beginner

Joined: Tue Jul 25, 2006 12:34 pm
Posts: 25
Could someone tell me why Hibernate is putting my key fields at the END of the insert statement?

If the position of the fields is vital why is it/would it use any order OTHER THAN THAT DEFINED IN THE MAPPING DOCUMENT?!

We use Stored Procedures heavily here and in the current project they are mandatory due the complexity of the data and logic behind the effective-dated records. In our case the update SP just calls the add SP which then inserts a new record which supersedes the previous one.

The SP parameter lists were created months ago along with the thick-client application that we use internally to manage the database. Now I'm trying to call the same SPs and I get all these bizzare errors which smack of a parameter sequencing issue. And so it is (see below).

I cannot change the sequence of the parameters of hundreds of SPs that are already in production. If I was using custom SQL in the mapping file, I could alter things as necessary to accommodate Hibernate. That cannot happen with an SP.

How do I tell Hibernate to sequence the fields as defined in the mapping document?

Hibernate version: 3.02

Mapping documents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping package="us.tx.state.oag.ApplicationSecurity.db">

<class name="InfoPhone" table="info_phone" schema="dbo" catalog="application_security">

<composite-id name="id" class="us.tx.state.oag.ApplicationSecurity.db.InfoPhoneId">
<key-property name="ownerTypeId" type="java.math.BigDecimal">
<column name="owner_type_id" precision="18" scale="0" />
</key-property>
<key-property name="phoneId" type="java.math.BigDecimal">
<column name="phone_id" precision="18" scale="0" />
</key-property>
<key-property name="parentId" type="java.math.BigDecimal">
<column name="parent_id" precision="18" scale="0" />
</key-property>
<key-property name="phoneTypeId" type="java.math.BigDecimal">
<column name="phone_type_id" precision="18" scale="0" />
</key-property>
<key-property name="dtEffective" type="java.sql.Timestamp">
<column name="dt_effective" length="23" />
</key-property>
</composite-id>
<property name="inactive" type="java.lang.Integer">
<column name="inactive" />
</property>
<property name="isPrimary" type="java.lang.Integer">
<column name="is_primary" not-null="true" />
</property>
<property name="phoneName" type="java.lang.String">
<column name="phone_name" length="60" not-null="true" />
</property>
<property name="phoneNumber" type="java.lang.String">
<column name="phone_number" length="20" not-null="true" />
</property>
<property name="phoneExtension" type="java.lang.String">
<column name="phone_extension" length="10" />
</property>
<property name="crUser" type="java.lang.String">
<column name="cr_user" length="20" not-null="true" />
</property>
<property name="crDate" type="java.sql.Timestamp">
<column name="cr_date" length="23" not-null="true" />
</property>
<property name="upUser" type="java.lang.String">
<column name="up_user" length="20" not-null="true" />
</property>
<property name="upDate" type="java.sql.Timestamp">
<column name="up_date" length="23" not-null="true" />
</property>
<!--
<sql-insert callable="true">
<![CDATA[
{ call info_phone_spa(?,?,?,?,?,?,?,?,?,?,?,?,?,?,0) }
]]>
</sql-insert>
<sql-update callable="true">
<![CDATA[
{ call info_phone_spu(?,?,?,?,?,?,?,?,?,?,?,?,?,?) }
]]>
</sql-update>
-->
<!-- NOTE: Per AppSec retention requirements, there is no
deletion SP; records must be updated with INACTIVE=1. -->

</class>

<!-- NOTE: the first parameter, owner-type = 1 for users -->
<sql-query name="userPhoneNumbers" callable="true">
<return alias="userPhone" class="InfoPhone"/>
<![CDATA[
{ call info_phone_on_file_spr(1,?) }
]]>
</sql-query>

<!-- NOTE: the first parameter, owner-type = 2 for companies -->
<sql-query name="companyPhoneNumbers" callable="true">
<return alias="companyPhone" class="InfoPhone"/>
<![CDATA[
{ call info_phone_on_file_spr(2,?) }
]]>
</sql-query>

<!-- NOTE: requires the entire key be supplied -->
<sql-query name="getPhoneNumber" callable="true">
<return alias="infoPhone" class="InfoPhone"/>
<![CDATA[
{ call info_phone_spr(?,?,?,?,?) }
]]>
</sql-query>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

lo_sess.save(po_phoneNumber);
lo_trans.commit();


Name and version of the database you are using: Sybase 12.x

The generated SQL (show_sql=true):
insert
into
application_security.dbo.info_phone
(inactive, is_primary, phone_name, phone_number, phone_extension, cr_user, cr_date, up_user, up_date, owner_type_id, phone_id, parent_id, phone_type_id, dt_effective)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

SP header that needs to be called
CREATE PROCEDURE info_phone_spu (
@owner_type_id dc_identifier,
@phone_id dc_identifier,
@parent_id dc_identifier,
@phone_type_id dc_identifier,
@dt_effective dt_last_update,
@inactive b_flag,
@is_primary b_flag,
@phone_name s_desc_long,
@phone_number s_phone_num,
@phone_extension varchar(10),
@cr_user s_who,
@cr_date dt_last_update,
@up_user s_who,
@up_date dt_last_update
)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 12:39 pm 
Newbie

Joined: Mon Sep 25, 2006 4:44 pm
Posts: 4
I am also helping to design an application that needs to interact with predefined stored procedures. The "persistence with hibernate" book indicates that a future release of hibernate will support named parameters. Is there any plan to include this in the next release of hibernate?

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.