Hi all,
I'm a newbie in Hibernate and trying to run the example in the "Hibernate In Action" book. Please give as detailed help as possible.
Hibernate Version
2.1.6
Mapping Documents
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="hibernate.Message"
table="MESSAGES">
<id
name="id"
column="MESSAGE_ID">
<generator class="increment"/>
</id>
<property
name="text" column="MESSAGE_TEXT"/>
<many-to-one
name="nextMessage"
cascade="all"
column="NEXT_MESSAGE_ID"/>
</class>
</hibernate-mapping>
Code between session.open() and session.close()Code:
Message message = new Message("Hello World");
session.save(message);
ExceptionCode:
WARNING: SQL Error: 233, SQLState: 23502
Dec 12, 2005 3:51:13 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ASA Error -195: Column 'NEXT_MESSAGE_ID' in table 'MESSAGES' cannot be NULL
Dec 12, 2005 3:51:13 PM net.sf.hibernate.JDBCException <init>
SEVERE: could not insert: [hibernate.Message#1]
com.sybase.jdbc2.jdbc.SybSQLException: ASA Error -195: Column 'NEXT_MESSAGE_ID' in table 'MESSAGES' cannot be NULL
Database name and versionMySQL 4.1.10
The generated SQL (show_sql=true):Hibernate: insert into MESSAGES (MESSAGE_TEXT, NEXT_MESSAGE_ID, MESSAGE_ID) values (?, ?, ?)
Declaration of class I try to persistCode:
package hibernate;
public class Message
{
private Long id;
private String text;
private Message nextMessage;
private Message(){};
public Message( String text)
{
this.text = text;
}
/**
* @return Returns the id.
*/
public Long getId ( )
{
return id;
}
/**
* @param id The id to set.
*/
public void setId ( Long id )
{
this.id = id;
}
/**
* @return Returns the nextMessage.
*/
public Message getNextMessage ( )
{
return nextMessage;
}
/**
* @param nextMessage The nextMessage to set.
*/
public void setNextMessage ( Message nextMessage )
{
this.nextMessage = nextMessage;
}
/**
* @return Returns the text.
*/
public String getText ( )
{
return text;
}
/**
* @param text The text to set.
*/
public void setText ( String text )
{
this.text = text;
}
}
Best regards
/Andreas