-->
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.  [ 1 post ] 
Author Message
 Post subject: ms sqlserver rowguid (not used as pk)
PostPosted: Thu Apr 21, 2005 9:45 am 
Newbie

Joined: Thu Apr 21, 2005 7:56 am
Posts: 1
Location: Germany
hello,

i am new to hibernate and have a problem with rowguids in sqlserver2k.
every table we use has a rowguid column which is NOT the primary key.
this column is mainly used for the replication of the database but in fact has to be mapped to an object, too.
we use the "newid()"-function of sqlserver as the default value for the column. i saw that this can also be handled by hibernate, but only for the primary key (id). when i leave the rowguid in my newly created object "null", i get the exception listed below which is clear and was expected. is there a way to let the database generate the uniqueidentifer for the rowguid but still use it in the pojo and have it set to "not-null"? or can i use a hibernate generator for the rowguid even if the column is NOT the primary key?
i searched the forum on this topic and read the docs but didn't find an answer.

thank you in advance,
jan

example sql-script:
CREATE TABLE [dbo].[User] (
[UserID] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL ,
[Username] [varchar] (50) COLLATE Latin1_General_CI_AS NOT NULL ,
[FirstName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[LastName] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[rowguid] uniqueidentifier ROWGUIDCOL NOT NULL
) ON [PRIMARY]

Hibernate version:
hibernate 2.1.8

Mapping documents:
User.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="user">

<class name="User" table="User">
<id name="userid" column="UserID" type="java.lang.Integer">
<generator class="identity">
</generator>
</id>

<property name="username" column="Username" type="java.lang.String" not-null="true" />
<property name="firstname" column="FirstName" type="java.lang.String" />
<property name="lastname" column="LastName" type="java.lang.String" />
<property name="rowguid" column="rowguid" type="java.lang.String" not-null="true" />
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: user.User.rowguid
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1286)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:937)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:866)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:784)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:747)
at HibernateTest.main(HibernateTest.java:20)

Name and version of the database you are using:
ms sqlserver 2000
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.