Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unneccessary database changeSet related to boolean after grails 2.4.3 upgrade

I am using postgres database. After upgading to grails 2.4.3 I get database changeset of this type for all boolean fields:

changeSet(author: "me(generated)", id: "1383573084784-1") {
    addColumn(tableName: "chapter") {
        column(defaultValue: true, name: "is_framable", type: "boolean") {
            constraints(nullable: "false")
        }
    }
}

isFramable is a boolean field in the domain class Chapter. Even after running this migration it's generated everytime by dbm-gorm-diff

I noticed that in older versions of grails there used to be bool instead of boolean in the changesets

I am using hibernate version 4.3.5.5

like image 944
vishesh Avatar asked Oct 10 '14 11:10

vishesh


1 Answers

My workaround for that:

Config.groovy

grails.gorm.default.mapping = {
    "user-type" type: my.hibernate.type.BooleanBitType, class: boolean
    "user-type" type: my.hibernate.type.BooleanBitType, class: Boolean
}

BooleanBitType.java

import my.hibernate.type.descriptor.BooleanBitTypeDescriptor;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;

public class BooleanBitType extends org.hibernate.type.BooleanType {
    public static final BooleanBitType INSTANCE = new BooleanBitType();

    public BooleanBitType() {
        this(BooleanBitTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE);
    }

    protected BooleanBitType(SqlTypeDescriptor sqlTypeDescriptor, BooleanTypeDescriptor javaTypeDescriptor) {
        super(sqlTypeDescriptor, javaTypeDescriptor);
    }
}

BooleanBitTypeDescriptor.java

public class BooleanBitTypeDescriptor extends org.hibernate.type.descriptor.sql.BooleanTypeDescriptor {
    public static final BooleanBitTypeDescriptor INSTANCE = new BooleanBitTypeDescriptor();

    public BooleanBitTypeDescriptor() {
        super();
    }

    public int getSqlType() {
        return Types.BIT;
    }
}
like image 136
AndreyT Avatar answered Oct 03 '22 02:10

AndreyT