-->
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.  [ 2 posts ] 
Author Message
 Post subject: Column 'NEXT_MESSAGE_ID' in table 'MESSAGES' cannot be NULL
PostPosted: Mon Dec 12, 2005 11:04 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 6:16 am
Posts: 40
Location: Luxembourg
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);


Exception
Code:
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 version
MySQL 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 persist
Code:
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 11:15 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 6:16 am
Posts: 40
Location: Luxembourg
Forgot to attach the table creation script :

Code:
Create table MESSAGES
(
MESSAGE_ID  INTEGER NOT NULL,
MESSAGE_TEXT  VARCHAR(36),
NEXT_MESSAGE_ID INTEGER,
)


Best regards
/Andreas
[/code]


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

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.