-->
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.  [ 10 posts ] 
Author Message
 Post subject: sql-server, trigger, generated key
PostPosted: Mon Apr 05, 2004 11:51 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
Hello there
I'm trying to make my app work on SQL-server 2000 with JTDS 0.8-rc1, and Hibernate 2.1.2. This new driver seems to work better than the earlier (which never worked for me), so I decided to give SQL-server one last try before settling on MaxDB (which is great).

SQL-server allows null value(s) in columns with unique constraint, but treats mulitple null values as duplicates. This meas that you are only allowed to insert one row with a null value for the unique column. I don't get the point of this, as ANSI SQL92 says that null = null = false, but created a workaround using a trigger on insert and update, like this:

Code:
create trigger check_format_nativename
on dbo.itemformat
for insert, update
as
   if(select max(cnt)
   from (select count(inserted.nativename) as cnt from
   itemformat, inserted where
   itemformat.nativename = inserted.nativename
   group by inserted.nativename) x) > 1
begin
   raiserror ('Nativename must be unique', 1, 1)
   ROLLBACK TRANSACTION
end
go


which checks the constraint as it should. Problem is, that the generated ID from the insert statement is not returned (or available) for Hibernate (or JTDS), which gives me te following SQLException:

Code:
Expected generated keys ResultSet


When I do a manual insert, followed by an select @@IDENTITY, the generated key is returned. Anyone got an idea?

Tnx
milx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 4:28 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
milx,

It seems like this is a bug in jTDS that we (the jTDS developers) did not know about. The combination of triggers and calling getGeneratedKeys() seems to not work well together (because triggers are generating additional update counts while getGeneratedKeys() expects a ResultSet right after the first update count). I'll submit this as a jTDS bug and we'll try to fix it as soon as possible (Hibernate compatibility is one of our major short-term goals).

In the meantime, I think that the current CVS version of jTDS might just work with this particular trigger (not with any trigger) because of recent changes. If you are interested enough, you can download and build it yourself.

Alin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 4:58 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
alin_sinpalean wrote:
I'll submit this as a jTDS bug and we'll try to fix it as soon as possible (Hibernate compatibility is one of our major short-term goals).


For the record, here's the jTDS bug report: https://sourceforge.net/tracker/index.p ... tid=407762

Alin.


Top
 Profile  
 
 Post subject: tnx
PostPosted: Tue Apr 06, 2004 7:27 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
Thanks for the effort alin. I will check JTDS later, stick with MaxDB for now.
milx


Top
 Profile  
 
 Post subject: jtds
PostPosted: Tue Apr 06, 2004 8:32 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
Hello again
It (triggers) works with JTDS (you probably know). Another possible bug with jTDS is that database names containing a "-" character, for instance "sl-server", does not work. It's supported by SQL-server, and works with JTDS. Again, thanks, and lets hope the new MICROSUN technology compabillity effort (or hype) comes up with a desent driver....
milx


Top
 Profile  
 
 Post subject: Re: jtds
PostPosted: Wed Apr 07, 2004 4:38 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
milx wrote:
It (triggers) works with JTDS (you probably know).


Indeed, jTDS can ignore trigger-generated update counts if you set the lastUpdateCount parameter to true. However, this only works with executeUpdate and if generated keys are not requested.

milx wrote:
Another possible bug with jTDS is that database names containing a "-" character, for instance "sl-server", does not work. It's supported by SQL-server, and works with JTDS.


What do you mean? Do you get any exception when using database names containing a minus? If so, could I see the stack trace? I also suppose you meant it's supported by SQL-server, and works with the Microsoft driver.

milx wrote:
Again, thanks, and lets hope the new MICROSUN technology compabillity effort (or hype) comes up with a desent driver....


What's MICROSUN? I've searched with Google and I only came up with lamp manufacturers and small IT companies that were too lazy to come up with a name of their own.

Alin.


Top
 Profile  
 
 Post subject: misunderstandings
PostPosted: Wed Apr 07, 2004 5:22 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
I wrote:
Quote:
It (triggers) works with JTDS (you probably know).

Should be:
Quote:
It (triggers) works with JSQLConnect (you probably know).

Same here:
Quote:
It's supported by SQL-server, and works with JTDS.

Should be:
Quote:
It's supported by SQL-server, and works with JSQLConnect .


alin wrote
Quote:
If so, could I see the stack trace?


Sorry, renamed the database, will post if I see it again.


Also sorry about the misspellings, and even more sorry if you searched in vain for MICROSUN. Though some people think it's a future possibillity, Sun Microsystems and Microsoft are still two separate compaines. If you missed the latest check http://www.theserverside.com/news/thread.tss?thread_id=24883 for links and discussion.

milx


Top
 Profile  
 
 Post subject: Re: misunderstandings
PostPosted: Wed Apr 07, 2004 7:16 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Ok, I understand. No problem.

About database names containing "weird" characters (such as minus), jTDS should work just fine as long as they are escaped (e.g. [my-db]). I'll get back to you when we fix the trigger-getGeneratedKeys problem.

Alin.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 9:34 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
Again, thanks.
milx


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 6:11 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
Hello
There has been done some work on this, see http://sourceforge.net/tracker/index.php?func=detail&aid=930305&group_id=33291&atid=407762. I checked the latest verison from CVS, compiled and ran my test suite successfully both with and without triggers in the database. I did not use the
Code:
lastUpdateCount=true
parameter in the connection string, so the workaround seems to work (: Keep up the good work guys!

milx


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