My User
entity class contains password hash field, which is a byte array with a fixed length (32 since it's an SHA-256 hash).
@Entity
public class User {
@Column(nullable=false)
private byte[] passwordHash;
...
}
As you can see, I haven't annotated it with anything special, just a NOT NULL.
This works, but will it perform? My schema is generated by Hibernate, but I don't know exactly what it generates (I'm currently using an in-memory HSQL database).
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), it will store this hash in a BLOB field which is added in the record as a pointer (if I understand correctly how databases work).
Is this true, and how can I change this? Should I just encode the hash as a string, with base64 or hex, accepting the small performance/correctness impact of that?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With