-->
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.  [ 4 posts ] 
Author Message
 Post subject: SQL Server 2000 native id generation
PostPosted: Tue Oct 26, 2004 8:06 pm 
Newbie

Joined: Mon Jul 26, 2004 2:52 pm
Posts: 11
Hibernate version: 2.1.4

Mapping documents:

<class name="User" table="PLT_USER">

<cache usage="read-write"/>
<id name="id" type="long" column="ID" unsaved-value="null">
<generator class="native"/>
</id>


Full stack trace of any exception that occurs:

2004-10-26 16:17:24,240 DEBUG [util.JDBCExceptionReporter] [PoolThread-9] SQL Exception
com.jnetdirect.jsql.x: Invalid object name 'hibernate_unique_key'.
at com.jnetdirect.jsql.x.a(Unknown Source)
at com.jnetdirect.jsql.az.a(Unknown Source)
at com.jnetdirect.jsql.ai.g(Unknown Source)
at com.jnetdirect.jsql.ai.new(Unknown Source)
at com.jnetdirect.jsql.ai.for(Unknown Source)
at com.jnetdirect.jsql.m.execute(Unknown Source)
at com.jnetdirect.jsql.ai.long(Unknown Source)
at com.jnetdirect.jsql.at.executeQuery(Unknown Source)
at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:93)
at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:59)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1387)


Name and version of the database you are using:
Sql Server 2000

I have configured to use native id generation scheme and intend Hibernate to use the SQL Server Identity scheme. The schema generated by the Hibernate export tool looks right. However when I try to create and save objects, Hibernate seems to default to HiLo generator. I am using the net.sf.hibernate.dialect.SQLServerDialect

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 1:59 am 
Newbie

Joined: Sat Aug 30, 2003 12:37 pm
Posts: 16
Replace :

<id name="id" type="long" column="ID" unsaved-value="null">
<generator class="native"/>
</id>

With this:

<id column="ID" name="id" type="long" unsaved-value="null" >
<generator class="identity" />
</id>


Why? Because SQL Servers uses identity for surrogate key generation.

Please read : http://www.hibernate.org/hib_docs/refer ... -sequences


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 2:49 am 
Newbie

Joined: Mon Sep 27, 2004 9:40 am
Posts: 11
Location: Ostrava, Czech Republic
I don't think changing native generator to identity is necessary, even reference says that native generator "picks identity, sequence or hilo depending upon the capabilities of the underlying database".

I use native generator for MS SQL Server 2000 successfuly (Hibernate version 2.1.6) and the only difference is that I use java.lang.Long type for id, so unsaved-value="null" is correct value for new instances of my class. I'm not sure if unsaved-value="null" works for ids of the long type as well. Maybe you can try unsaved-value="0" which is the default value for long type.

my mapping:
<id name="id" column="ID" type="java.lang.Long" unsaved-value="null">
<generator class="native">
</generator>
</id>

HTH,
Pavel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 8:40 am 
Newbie

Joined: Wed Oct 27, 2004 5:54 am
Posts: 6
We've got SQL server here and I must use : <generator class="vm"> to generate ID.

"Native" and "identity" don't work.

I didn't find anything about <generator class="vm"/>... :-(


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