-->
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.  [ 6 posts ] 
Author Message
 Post subject: [SQLServer2000] Only works with <generator class="vm
PostPosted: Wed Oct 27, 2004 6:15 am 
Newbie

Joined: Wed Oct 27, 2004 5:54 am
Posts: 6
Hello,


Trying my first test with Hibernate, I used HibernateSynchroniser to generate the mapping file of a simple table (ID, text).

Hibernate Synchroniser gives me a <generator class="vm" /> for the primary key. I changed this to "identity" (as the manual said for SQL Server).

I didn't find anything about <generator class="vm" /> on the forum or in the online docs.

My problem is that I can't insert anything if I use <generator class="identity" /> (or "native") but it's okay with <generator class="vm" />.

Below, I provide the Stack trace and the generated SQL.

My question is : What is <generator class="vm" /> ???



Hibernate version: 2.1.6

Mapping documents:
<hibernate-mapping package="test">
<class name="TauxTva" table="TAUXTVA">
<id
column="TauxTVAID"
name="id"
type="int"
>
<generator class="identity" />
</id>
<property
column="TauxTVA"
length="53"
name="TauxTVA"
not-null="true"
type="float"
/>
</class>
</hibernate-mapping>


Full stack trace of any exception that occurs:
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Can't insert NULL in column 'TauxTVAID', table 'TEST.dbo.TAUXTVA'. This column doesn't accept NULL value. INSERT a


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 6:16 am 
Newbie

Joined: Wed Oct 27, 2004 5:54 am
Posts: 6
Another question could be : Why "native" and "identity" don't work ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 6:28 pm 
Newbie

Joined: Fri Oct 29, 2004 1:05 pm
Posts: 10
I have the same behaviour and the same questions. Anyone know?

L


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 4:52 am 
Newbie

Joined: Wed Oct 27, 2004 5:54 am
Posts: 6
In fact, it works.

Here, I switched to "native" for IDs and it works.

In fact, it was our fault : we didn't select the primary key in the table panel to be automatically incremented.

I think generator="vm" means "Select max(id)" and do (max+1) for insert(id, ...)

Generator="native" relies on SQL Server to produce a valid ID.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 7:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
vm = increment, they are the same. use of the term vm is deprecated.

native is meant for portability. it says to use the capabilities supported by the underlying database. for sql-server, this would translate into the use of the IdentityGenerator class, which relies on the databases ability to mark the pk column for auto-increment.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 8:32 am 
Newbie

Joined: Wed Oct 27, 2004 5:54 am
Posts: 6
Thanks Steve, for the answer.


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