-->
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.  [ 11 posts ] 
Author Message
 Post subject: IDENTITY_INSERT must be on in SQLServer -cannot flush
PostPosted: Wed Mar 10, 2004 3:03 am 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
Using the Increment Generator I can save an obejct with an int key with SQLServer -
However when I flush I get the following errorjava.sql.SQLException: Cannot insert explicit value for identity column in table 'Products' when IDENTITY_INSERT is set to OFF
I thnk that the DB is supposed to generate an ID but how do I declare to use this capability.



Caused by: java.sql.SQLException: Cannot insert explicit value for identity column in table 'Products' when IDENTITY_INSERT is set to OFF.
at net.sourceforge.jtds.jdbc.SqlMessage.toSQLException(SqlMessage.java:85)
at net.sourceforge.jtds.jdbc.SQLWarningChain.addOrReturn(SQLWarningChain.java:99)
at net.sourceforge.jtds.jdbc.TdsStatement.getMoreResults(TdsStatement.java:709)
at net.sourceforge.jtds.jdbc.TdsStatement.executeCallImpl(TdsStatement.java:231)
at net.sourceforge.jtds.jdbc.TdsStatement.internalExecuteCall(TdsStatement.java:214)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.execute(PreparedStatement_base.java:180)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeUpdate(PreparedStatement_base.java:235)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)

_________________
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 3:14 am 
Newbie

Joined: Sat Jan 03, 2004 11:35 am
Posts: 9
Location: Austria
<class >
<id unsaved-value="0" column="id" type="int" name="id">
<generator class="identity"/>
</id>

<property ....>
......
</class>

guenz


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 12:09 pm 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
java.lang.RuntimeException: net.sf.hibernate.MappingException: Dialect does not support identity key generation

I am using SQLServer 2000

_________________
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You have not set the right dialect in your configuration.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 12:40 pm 
Newbie

Joined: Sat Jan 03, 2004 11:35 am
Posts: 9
Location: Austria
i'm using sql server 2000 too and it works fine.


Top
 Profile  
 
 Post subject: which Dialect
PostPosted: Wed Mar 10, 2004 2:22 pm 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
which Dialect - and I am talking to the northwind database

_________________
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 2:55 pm 
Newbie

Joined: Sat Jan 03, 2004 11:35 am
Posts: 9
Location: Austria
net.sf.hibernate.dialect.SQLServerDialect


Top
 Profile  
 
 Post subject: Cannot insert explicit value for identity column in table
PostPosted: Thu Apr 21, 2005 11:08 pm 
Newbie

Joined: Thu Apr 21, 2005 9:34 pm
Posts: 4
I too am using MS Sqlserver 2000 and Hibernate 2.1.8 and am getting the same error message:


Cannot insert explicit value for identity column in table 'Session' when IDENTITY_INSERT is set to OFF


guenz wrote:
net.sf.hibernate.dialect.SQLServerDialect


I am using the above dialect and also this code

Code:
<id name="sessionId" type="int" column="SESSION_ID" unsaved-value="null">
   <generator class="identity" />
</id>


I have the SESSION_ID column set to Identity=Yes on the Sqlserver database table, so there should not be a matchup problem between the generator and the identity column.

When I first encountered this problem, I was using the Microsoft driver until I found the FAQ in which it is stated that the MS driver is not supported in Hibernate. I then installed the JSQLConnect driver and still got the same error message


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 7:40 am 
Newbie

Joined: Fri Apr 15, 2005 8:08 am
Posts: 6
I am using sqlserver 2000 and it works fine in this situation.

hibernate-configuration:

<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

CustomerOrderHistory.xml:

<id
name="CustomerOrderHistoryId"
type="java.lang.Integer"
>
<column name="CustomerOrderHistoryId" length="10" not-null="true" unique="true" sql-type="int identity" />
<generator class="identity" />
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 9:02 am 
Newbie

Joined: Thu Apr 21, 2005 9:34 pm
Posts: 4
Ke wrote:
I am using sqlserver 2000 and it works fine in this situation.

hibernate-configuration:

<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

CustomerOrderHistory.xml:

<id
name="CustomerOrderHistoryId"
type="java.lang.Integer"
>
<column name="CustomerOrderHistoryId" length="10" not-null="true" unique="true" sql-type="int identity" />
<generator class="identity" />
</id>


I tried this in my hbm file and still got the same error. I do however notice you are using a different driver (jtds). I will try downloading this other driver and trying your solution again with that driver.


Thanks,
Paolo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 10:54 am 
Newbie

Joined: Thu Apr 21, 2005 9:34 pm
Posts: 4
A little update:

I got my Session object successfully inserted. I did it by doing the following:

1. setting my generator to "increment"
2. not setting my primary key to identity.
3. removing the association I had between Session and a linking table:

Code:
<many-to-one
         name="sessionContent"
         column="session_id"
         class="com.mycompany.SessionContent"
         not-null="false" />


So I guess the next step for me is to reread the documentation and Hibernate books that I have access to on how to properly set up associations. As I have found, an incorrectly coded association can make life miserable.

Thanks for the help!


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