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.  [ 7 posts ] 
Author Message
 Post subject: sql-insert not working for me in 1.2 beta 2
PostPosted: Mon Jan 08, 2007 5:29 pm 
Newbie

Joined: Mon Jan 08, 2007 5:19 pm
Posts: 4
1.2 Beta 2 against SQL Server 2005

I can't seem to get the <sql-insert> override to work for me. sql-delete and sql-update work fine but no matter what I do the insert tries to use its own INSERT statement instead.

am I doing something wrong?

here is my very simple mapping:

<class name="DocumentData" table="Document" lazy="false">
<id name="ID" type="long">
<generator class="native" />
</id>
<property name="Comment" type="String" />
<sql-insert>exec SetDocument ?, ?</sql-insert>
<sql-update>exec SetDocument ?, ?</sql-update>
<sql-delete>exec DeactivateDocument ?</sql-delete>
</class>


I am using the table reference in the class so that I get an automatic SELECT statement built for me, but I want to handle the filing myself. I tried removing the table reference and using a custom loader but then it tried to use an INSERT statment against the class name instead of the table name.

is it the fact that I have an "id" defined for the table? should I just make that a regular "property" instead?

any advice is most appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 3:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
sql-insert doesn't work with native generators. Change to a different identifier generation strategy.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 12:47 pm 
Newbie

Joined: Mon Jan 08, 2007 5:19 pm
Posts: 4
thanks Sergey.

changing the generator type definitely made it start using the stored procedure for inserts, but now I have a new problem...

I have an existing database, and as part of that the same stored procedures are being used for both inserts and updates (as you can see in my mapping). in my current application I am generating the ID field for the object/row within the stored procedure and returning that as either an output parameter or return value - so for an insert I would provide an ID = 0 and the procedure would know to do an insert and generate the ID for me, for an update I would just pass in the actual ID of the row and the procedure knows to do an update instead.

so what I would like NHibernate to do in this case is to use the stored procedure for the insert, and ALSO be able to automatically populate the ID in the object subsequent to that procedure call. this doesn't seem possible without some kind of output parameter/return value coming from the procedure and some way of telling NHibernate to look at it.

have a run into a show stopper (assuming I can't change the way my database/procedures currently work)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 2:05 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate does not currently support returning identifiers from stored procedures or using them to generate an identifier, unfortunately.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 09, 2007 4:35 pm 
Newbie

Joined: Mon Jan 08, 2007 5:19 pm
Posts: 4
thanks again Sergey. I recognize that what I am doing is not necessarily a mainstream case... I guess I am trying too many "tricks" at once :-)


Top
 Profile  
 
 Post subject: Which generator class to make sql-insert stored proc work?
PostPosted: Fri Jan 19, 2007 7:35 pm 
Newbie

Joined: Wed Nov 22, 2006 1:45 pm
Posts: 3
Hi mcole_ge and sergey,

can you pls. let me know which generator class you are using to make it work?

Many thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 21, 2007 1:33 pm 
Newbie

Joined: Mon Jan 08, 2007 5:19 pm
Posts: 4
I think I used "assigned"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.