Home Why does SqlExceptionHelper interpret boolean constraint violation as \x00
Reply: 1

Why does SqlExceptionHelper interpret boolean constraint violation as \x00

ThatGuyGrant
1#
ThatGuyGrant Published in 2018-01-12 09:09:49Z

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

Kayaman
2#
Kayaman Reply to 2018-01-12 09:13:31Z

\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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30368 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO