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]