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