java - EclipseLink Sql-Server IDENTITY_INSERT ERROR -
using eclipselink, trying insert rows sqlserver legacy db has auto-incrementing identity column:
create table [dbo].[tcontacts] ( [conidcontact] [int] identity (1, 1) not null , [concontactname] [varchar] (100) not null , ...
i using 'identity" strategy described in
http://en.wikibooks.org/wiki/java_persistence/identity_and_sequencing#example_identity_xml
<orm:id name="id"> <generated-value strategy="identity"/> <orm:column name="conidcontact" updatable="false" /> </orm:id>
eclipselink produces following sql:
call: insert tcontacts (conidcontact, concontactname, ... values (?, ?, ... bind => [null, testheini_2, ...
resulting in following exception:
internal exception: 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
(sorry german, tells no value can inserted identity column long identity_insert set off, default)
i assume sqlserver wants create id not eclipselink tries insert value (here: null) id-column.
other strategies, or omitting generated-value stragegy alltogether, produce same result.
far have found no way eclipselink insert records table!
setting identity insert on no viable solution, because standard user should not have rights modify table.
mapping table in hibernate straightforward, surprised seems impossible eclipselink. here how did in hibernate:
<id name="id" type="int"> <column name="conidcontact" /> <generator class="assigned" /> </id>
i stuck , appreciate ideas going wrong here!
hannes
@chris: persist that:
con.setname("testheini_2");
em.gettransaction().begin();
em.persist(con);
em.gettransaction().commit();
contact-orm.xml file used indeed, can see add typo.
added
property name="eclipselink.target-database" value="sqlserver"
or
property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.sqlserverplatform"
persistence.xml, not make difference. else check?
hannes
Comments
Post a Comment