For a long time, SQL and Booleans have not gotten along.  Standards for SQL never really addressed the need for boolean data -- it was assumed that some other data type could easily just step in and address this need.  The result was a lot of different data models for boolean values.  Here are some examples.
- TRUE or FALSE
- T or F
- Y or N
- 1 or 0
- <any value> vs NULL
The internet shows the debate has gone on, even as SQL standards have changed.  Coming from a professional background with Oracle, I struggled with this across my teams because everyone had a different opinion, which led to a lot of time wasted due to debate.
This said, I appreciate working with native queries in hibernate's JPA implementation against MySQL.  MySQL supports a BIT data type I recently discussed.  When we represent data in MySQL with BIT and restrict the length to just 1 (ie 1 bit), Hibernate JPA magically knows to query and return this data as a Boolean in the data returned by getResultList().  This kind of magic helps to solve the problem easily and gets rid of lots of debate.
Comments
Post a Comment