SQLServer IDENTITY_INSERT fails --SOLVED [message #1072710] |
Tue, 23 July 2013 06:40  |
Eclipse User |
|
|
|
Hello Everybody,
I am dealing with a SQLServer legacy DB which has an Identity column which auto-increments. Mapping this with hibernate was straightforward with no changes to the DB:
<id name="id" type="int">
<column name="conIdContact" />
<generator class="assigned" />
</id>
However, I am unable to get this to work with EclipseLink.
Whatever I try results in an SQLServer Exception complaining that the ID cannot be inserted because IDENTITY_INSERT is set to OFF (sorry its german but should be clear.)
com.microsoft.sqlserver.jdbc.SQLServerException: Ein expliziter Wert für die Identitätsspalte kann in der tContacts-Tabelle nicht eingefügt werden, wenn IDENTITY_INSERT auf OFF festgelegt ist.
Error Code: 544
The disturbing thing is that I have set IDENTITY_INSERT to *ON*, and following SQL works flawlessly:
INSERT tcontacts (conidcontact, concontactname)
VALUES (12246, 'test_insert') Doing the same via EclipseLink also produces above error.
Wikibooks recommends to use IDENTITY
<orm:id name="id">
<generated-value strategy="IDENTITY" />
<orm:column name="conIdContact" updatable="false" />
</orm:id>
which does not work.
Omitting the strategy does not work either, nor does using AUTO.
In desperation I thought about setting
but then I get (not at all unexpectedly)
Exception Description: There should be one non-read-only mapping defined for the primary key field [tContacts.conIdContact].
I am stuck now and would be *very* grateful if someone could explain what is going wrong here!
Hannes
[Updated on: Tue, 13 August 2013 10:35] by Moderator
|
|
|
|
|
Re: SQLServer IDENTITY_INSERT fails [message #1077302 is a reply to message #1076509] |
Thu, 01 August 2013 10:05   |
Eclipse User |
|
|
|
Chris,
reordering the tags makes no difference, also no warnings, but one error on FINEST:
[EL Finer]: Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
Strange thing is that in my little test project Eclipselink tries to insert '0' into the ID column while in the original project it tried to insert 'NULL'.
Sorry can't reproduce this now as I shot it and have to rebuild first.
Can't say anything about other tags because I used mapping files and not annotations. In the xml
id, basic, column, name, attribute-type, many-to-one, target-entity, join-column, cascade
worked as expected. Have not tried anything else so far (except embeddedables, which did not work as expected)
I filed a bug at
https://bugs.eclipse.org/bugs/show_bug.cgi?id=414203
Hannes
|
|
|
|
Re: SQLServer IDENTITY_INSERT fails [message #1085120 is a reply to message #1082420] |
Mon, 12 August 2013 09:30   |
Eclipse User |
|
|
|
Hello James,
here is the SQL for the table:CREATE TABLE [dbo].[tContacts] (
[conIdContact] [int] IDENTITY (1, 1) NOT NULL ,
[conContactName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
... I am also positive the orm.xml is beeing read, every typo triggers an exception.
As for the <orm:id name="id">, as its a legacy DB the column names are different from the attribute names, as in name:
<orm:basic name="name"><orm:column name="conContactName"/></orm:basic>
so I did the same for the id.
Will try without.
The DB so far is also used by an older application, so I would prefer to leave Identity generation as is, but I agree it causes its own rat-tail of problems.
Thanks for looking into it!
Hannes
[Updated on: Mon, 12 August 2013 09:35] by Moderator
|
|
|
|
|
Re: SQLServer IDENTITY_INSERT fails --SOLVED [message #1085911 is a reply to message #1085882] |
Tue, 13 August 2013 10:34  |
Eclipse User |
|
|
|
James, you are right. Just tried this half an hour ago. Works!
I will edit/close the bug report first thing tomorrow morning.
Fussed around to find the example where I picked up the orm: prefix. I see now that Texo generated the orm.xml like that. Thought it was necessary ...
Thanks!
Hannes
|
|
|
Powered by
FUDForum. Page generated in 0.04453 seconds