Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which datatype i should use for mapping to boolean

I want to map a db column to a boolean in hibernate.Which datatype i should use to map it?

tiny int? 

I will use reverse mapping in netbeans to generate POJOS

like image 949
akshay Avatar asked Jul 08 '11 06:07

akshay


People also ask

What is data type for boolean in MySQL?

Boolean Data TypeMySQL does not have a boolean (or bool) data type. Instead, it converts boolean values into integer data types (TINYINT). When you create a table with a boolean data type, MySQL outputs data as 0, if false, and 1, if true.

How do you create a boolean column in SQL?

In SQL Server, a Boolean Datatype can be created by means of keeping BIT datatype. Though it is a numeric datatype, it can accept either 0 or 1 or NULL values only. Hence easily we can assign FALSE values to 0 and TRUE values to 1. This will provide the boolean nature for a data type.

How do I select a boolean in MySQL?

MySQL does not contain built-in Boolean or Bool data type. They provide a TINYINT data type instead of Boolean or Bool data types. MySQL considered value zero as false and non-zero value as true. If you want to use Boolean literals, use true or false that always evaluates to 0 and 1 value.

How will you create a table with boolean data type in SQL Server?

CREATE TABLE testbool ( sometext TEXT, is_checked BOOLEAN ); You can insert a boolean value using the INSERT statement: INSERT INTO testbool (sometext, is_checked) VALUES ('a', TRUE); INSERT INTO testbool (sometext, is_checked) VALUES ('b', FALSE); When you select a boolean value, it is displayed as either 't' or 'f'.


2 Answers

Take BIT(1) in mysql and Boolean in java object

like image 158
jmj Avatar answered Nov 03 '22 01:11

jmj


tinyint(1) will map to boolean

bit will map to boolean as well, but when exporting bit with mysqldump will look like '\0' so i recommend tinyint(1) which will look like 0 or 1

like image 21
Esben Skov Pedersen Avatar answered Nov 03 '22 01:11

Esben Skov Pedersen