-->
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: Setting the default value of a field
PostPosted: Tue Jun 07, 2005 1:42 pm 
Newbie

Joined: Fri Feb 11, 2005 1:50 pm
Posts: 3
Apologise if this is far too simple, but I just don't seem to be able to achieve the following:

Hibernate version: 2.1.2

Name and version of the database you are using: MySQL 4.0.21


I have a "Message" class that contains the following variable with its getter method:


Code:
    private int generator = 0 ;

    /**
     * DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     *
     * [b]@hibernate.property not-null="true"[/b]
     */
    public int getGenerator() {
        return generator;
    }


What I'm trying to get is the "generator" field to be persisted and I'd like it to be created with a default value of 0.

Theoretically, setting not-null=true with the XDoclet declaration should make the field exactly that (NOT NULL), but I just can't see how I can set the default value.

Anyway, the database is created just fine, but the problem is that rather than setting the column as:
Code:
generator int[11] NOT NULL default '0'

what I get is (look like the not-null="true" is being ignored):
Code:
generator int[11] default NULL


I've been looking everywhere I know for an answer, but no luck....

Any ideas?

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 3:24 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
With which tool did you create the database schema?

I used the schemaexport ant task and it created:
Code:
create table message (
   id integer not null auto_increment,
   generator integer not null,
   primary key (id)
);


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.