0

I have the following domain object

@Table(uniqueConstraints={@UniqueConstraint(columnNames={"name", "company_id", "global"}, name="UC_name_companyId_global")})
@Entity
@Audited
public class AccessLevel implements Serializable, GlobalEntityInstance {

private static final long serialVersionUID = -7215569721971710808L;

  @Size(min = 2)
  @Column(nullable = false)
  private String name;

  @ManyToOne(optional = false)
  private Company company;

  @Column
  private boolean global = false;

  @Column(nullable = false)
  private GeneralStatus status;
}

The company attribute is mapped to column company_id.

I've created a test case to test that when an Access Level is added with the same 'name', 'company' and 'global' value a DataIntegrityViolationException is thrown. The excetion is being thrown, my questions is about the message:

o.h.engine.jdbc.spi.SqlExceptionHelper : Duplicate entry 'Temp Level-1-\x00' for key 'UC_name_companyId_global'

What in the heck is '\x00' (or '\x01' if true is saved) and why does the SqlExceptionHelper map/resolve a boolean value to it? Shouldnt the Duplicate entry key be 'Temp Level-1-false'?

Thanks in advance, Grant

UPDATE:

Im currently using MySQl 5.6

CodeNameGrant
  • 124
  • 4
  • 16
  • what is the underlying column type? – Maciej Kowalski Jan 12 '18 at 09:12
  • You can read about storing boolean in mysql in : [Which MySQL data type to use for storing boolean values](https://stackoverflow.com/questions/289727/which-mysql-data-type-to-use-for-storing-boolean-values) – AxelH Jan 12 '18 at 09:15
  • An a similar question but on Oracle : [What does Hibernate map a boolean datatype to when using an Oracle database by default?](https://stackoverflow.com/questions/1710198/what-does-hibernate-map-a-boolean-datatype-to-when-using-an-oracle-database-by-d) – AxelH Jan 12 '18 at 09:16

1 Answers1

2

\x00 is hex 0, and \x01 is hex 1. Commonly (but not always) used values for false and true. MySQL for example stores boolean columns as BIT(1), so it's working with 0/1 internally instead of true/false.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • Well, good thing they intend to fully implement booleans after version 5.1 https://bugs.mysql.com/bug.php?id=11881 – coladict Jan 12 '18 at 13:48
  • @Kayaman, Thanks for pointing this out. Do you know why the boolean is being mapped to a hex value? – CodeNameGrant Jan 15 '18 at 07:03
  • @ThatGuyGrant I don't really know why they chose hex representation for it instead of decimal, but since there's no concept of `true/false` at that level, it's going to show up in *some* number format. – Kayaman Jan 15 '18 at 09:31