-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate 2.1.x, MySQL alter table add column DDL
PostPosted: Tue Feb 17, 2004 7:18 pm 
Newbie

Joined: Sat Nov 01, 2003 5:42 pm
Posts: 6
Location: Chicago
Hello,

First, as always: Kudos to Hibernate team. Thanks for great project.

I've experienced a problem with a few versions of Hibernate 2.1.x. When adding a boolean field to a MySQL table with a not-null value set to true, the ddl comes out as:

alter table tablename add column booleancolumn BIT

leaving off the "NOT NULL"

Finally motivated to go a little deeper, I went into the src for the Table class and changed some code to include this. My question is: is this likely to cause any negative effects that aren't immediately obvious? I'm not too concerned about database independence for this particular product.

Thanks in advance.

Reid

code is from net.st.hibernate.mapping.Table.sqlAlterStrings v 2.1.2
Code:
         if (columnInfo==null) {
            // the column doesnt exist at all.
            StringBuffer alter = new StringBuffer( root.toString() )
               .append(' ')
               .append( col.getQuotedName(dialect) )
               .append(' ')
               .append( col.getSqlType(dialect, p) );
            if ( col.isUnique() && dialect.supportsUnique() ) {
               alter.append(" unique");
            }
// I added from here...
            if ( !col.isNullable()) {
               alter.append(" NOT NULL ");
            }
//...to here
            if ( col.hasCheckConstraint() ) {
               alter.append(" check(")
                  .append( col.getCheckConstraint() )
                  .append(")");
            }
            results.add( alter.toString() );
            

         }



_________________
--
Reid Carlberg
Five Sticks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 7:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is usually necessary to specify a default value when adding a column....


Top
 Profile  
 
 Post subject: not-null, default
PostPosted: Tue Feb 17, 2004 8:00 pm 
Newbie

Joined: Sat Nov 01, 2003 5:42 pm
Posts: 6
Location: Chicago
Hello,

Yes. However, in this particular case, MySQL does a nice job of saying if its a BIT, and null is not allowed, then default it to zero. At the very least, then, I should take that into the Dialect area? Not sure I'm ready for that tonight. ;-)

Just looking through the docs and DTD I don't see a setting that allows me to set a default there. Am I missing it?

Cheers,

Reid

_________________
--
Reid Carlberg
Five Sticks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.