Storing a hash as byte array with JPA
I'm concerned that, since it doesn't know that it's a fixed length array (the length field of the Column annotation applies to strings only), (...)
If you specify the column length, Hibernate will use this information to determine the SQL column type to generate (TINYBLOB
, BLOB
, MEDIUMBLOB
, LONGBLOB
) though.
What I need is BINARY(32)
Did you try this?
@Column(columnDefinition="BINARY(32) NOT NULL")private byte[] passwordHash;
As far as I know, a SHA-256 hash is always only printable characters (and if not, encode it base64), so the solution is that you CAN store it as string, then use the length
field of the Column
annotation.
Then you've got your fixed length and no doubt about performance.