-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with NATURAL id generator and SQL Server 2005
PostPosted: Thu Jul 19, 2007 6:42 am 
Newbie

Joined: Thu Jul 19, 2007 5:59 am
Posts: 3
Location: Romania
Hi,
I've already used Hibernate for a while, but this is my first time when I have a problem which I cannot solve by re-reading the relevant part of the manual. (Searching this forum didn't return any thread on a similar problem, I've only found with google another person asking about a very similar thing but without replay at: http://saloon.javaranch.com/78/001083.html )
I've developed an application that should function with an SQL Server database, but at the time of development was easier to use an Oracle 9i server. For this reason I used native in mapping-files as id-generator. When using Oracle9Dialect it used sequence (HIBERNATE_SEQUENCE) and on SQLServerDialect should be the equivalent of identity (right?).
The problem is: when inserting a new row (for a new entity), Hibernate generates an insert containing the ID column for which the value is not set (and this causes, obviously, SQLServerException: The value is not set for the parameter number X). I was hoping it would not include the ID column at all, so the database would auto-increment it.
The table is created with a script like:
CREATE TABLE [dbo].[TBL_UTILIZATOR] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[FK_GRUP] [int] NULL ,
[NUME] [varchar] (100) NOT NULL ,
[PRENUME] [varchar] (100) NOT NULL ,
[CNP] [varchar] (13) NULL ,
[LOGIN] [varchar] (16) NOT NULL ,
[PASSWORD] [varchar] (16) NOT NULL ,
[ACTIV] [bit] NOT NULL ,
[IP] [varchar] (16) NULL ,
CONSTRAINT [PK_TBL_UTILIZATOR] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]

I'm quite sure this must be just a little detail that I missed, but I have no clue what it is. Can anybody please help me?
Thanks in advance.

Hibernate version: 3.2.4.ga

Mapping documents:
<id name="id" column="ID" type="long">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>

Code between sessionFactory.openSession() and session.close(): session.saveOrUpdate(entity);

Full stack trace of any exception that occurs:
11:33:34,593 WARN JDBCExceptionReporter:77 - SQL Error: 0, SQLState: null
11:33:34,593 ERROR JDBCExceptionReporter:78 - The value is not set for the parameter number 9.
11:33:34,593 ERROR UtilizatorEditAction:158 - Rolled back Hibernate transaction because of:
org.hibernate.exception.GenericJDBCException: could not insert: [ro.uti.igpcc.model.Utilizator]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEv
entListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.j
ava:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener
.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java
:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at ro.uti.igpcc.dao.hibernate.GenericHibernateDAO.makePersistent(GenericHibernateDAO.java:86)
.....

Name and version of the database I'm using:
MS SQL Server 2005

The generated SQL (show_sql=true):
/* insert ro.uti.igpcc.model.Utilizator
*/ insert
into
TBL_UTILIZATOR
(FK_GRUP, NUME, PRENUME, CNP, LOGIN, IP, PASSWORD, ACTIV, ID)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?)

[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 10:12 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
This is a known issue:
http://opensource.atlassian.com/project ... e/HHH-2605

It's fixed in the SP1 release.

Cheers,

Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 12:37 pm 
Newbie

Joined: Thu Jul 19, 2007 5:59 am
Posts: 3
Location: Romania
Thanks a lot! It worked.

Too bad the bug is not so easy to find with google - it took me about a day.


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