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?
|