-->
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: Problems with null id field in SqlServer 2005
PostPosted: Wed Oct 24, 2007 11:19 pm 
Newbie

Joined: Wed Oct 24, 2007 11:02 pm
Posts: 2
WARNING: I'm very new to hibernate and just going through basic tutorials.

I'm going through chapter 2 tutorial from THE book as recommended in the quick start documentation.
However, I substituted HSQL with SqlServer 2005 database, and changed nextMessage to just a simple Long.

mapping:
<class
name="hello.Message"
table="MESSAGES">

<id
name="id"
column="MESSAGE_ID">
<generator class="native"/>
</id>

<property
name="text"
column="MESSAGE_TEXT"/>

<property
name="nextMessage"
column="NEXT_MESSAGE_ID" />

</class>

Class members:
public class Message {
private Long id;
private String text;
private Long nextMessage;
...}

This is the insert code:
Message message = new Message("Hello World");
session.save(message);

This is the hibernate log sql statement:
[java] Hibernate:
[java] /* insert hello.Message
[java] */ insert
[java] into
[java] MESSAGES
[java] (MESSAGE_TEXT, NEXT_MESSAGE_ID)
[java] values
[java] (?, ?)

In the database, the id field and the next id fields are both null, but the text field is is entered:
NULL Hello World NULL
NULL Hello World NULL
NULL Hello World NULL
NULL Hello World NULL


I thought the id field is automatically created by HIBERNATE session.
Do I need to create it manually for Sql Server?


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.