Depending on the Grails version booleans are stored differently; either as INT or BIT. BIT(1) is a special datatype made just for booleans. However old dogs prefer storing booleans as small int. In order to do this, you have to create a customized Hibernate dialect.
MySQL Example: foo.bar.brewsoftcorp.CustomMySQL5InnoDBDialect.groovy
package foo.bar.brewsoftcorp
import org.hibernate.dialect.MySQL5InnoDBDialect
import java.sql.Types
class CustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect {
CustomMySQL5InnoDBDialect() {
registerColumnType(Types.BIT, ‘boolean’)
}
}
package foo.bar.brewsoftcorp
import org.hibernate.dialect.MySQL5InnoDBDialect
import java.sql.Types
class CustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect {
CustomMySQL5InnoDBDialect () {
registerColumnType(Types.BIT, ‘boolean’)
}
}
SQL2000/2005 Example: foo.bar.brewsoftcorp.CustomSQLServerDBDialect.groovy
package foo.bar.brewsoftcorp
import org.hibernate.dialect.SQLServerDialect
import java.sql.Types
public class CustomSQLServerDBDialect extends SQLServerDialect {
public CustomSQLServerDBDialect() {
registerColumnType(Types.BIT, ‘boolean’)
}
}
Then add this line to your DataSource.groovy
dialect = util.CustomMySQL5InnoDBDialect //for MySQL
##############################
dataSource {
pooled = true
driverClassName = “com.mysql.jdbc.Driver”
username = “username”
password = “password”
dialect = util.CustomMySQL5InnoDBDialect
}
##############################
Depending on the Grails version booleans are stored differently; either as INT or BIT. BIT(1) is a special datatype made just for booleans. However old dogs prefer storing booleans as small int. In order to do this, you have to create a customized Hibernate dialect.
MySQL Example: foo.bar.brewsoftcorp.CustomMySQL5InnoDBDialect.groovy
package foo.bar.brewsoftcorp
import org.hibernate.dialect.MySQL5InnoDBDialect
import java.sql.Types
class CustomMySQL5InnoDBDialect extends MySQL5InnoDBDialect {
CustomMySQL5InnoDBDialect() {
registerColumnType(Types.BIT, ‘boolean’)
}
}
SQL2000/2005 Example: foo.bar.brewsoftcorp.CustomSQLServerDBDialect.groovy
package foo.bar.brewsoftcorp
import org.hibernate.dialect.SQLServerDialect
import java.sql.Types
public class CustomSQLServerDBDialect extends SQLServerDialect {
public CustomSQLServerDBDialect() {
registerColumnType(Types.BIT, ‘boolean’)
}
}
Then add this line to your DataSource.groovy
dialect = util.CustomMySQL5InnoDBDialect //for MySQL
##############################
dataSource {
pooled = true
driverClassName = “com.mysql.jdbc.Driver”
username = “username”
password = “password”
dialect = util.CustomMySQL5InnoDBDialect
}
##############################