Reputation: 5236
I have a prepraredStatement like below and I want to refactor this code and use Spring Data JPA. Problem is I don't know how to map java.sql.Types.BINARY to hibernate types.
String query= "SELECT count(*) FROM USERS WHERE ACCOUNT_ID=?";
query.setObject(1, accountID.toString().replaceAll("-", ""), Types.BINARY);
I tried byte array but when I query it returns empty resultset.
@Column(name = "ACCOUNT_ID", nullable = false)
private byte[] accountId;
Upvotes: 0
Views: 2131
Reputation: 1711
I'm not really sure that binary type is good for ID, may be you are using UUID and will benefit from it more?
But if you sure that this is what you actually want, then you can use org.hibernate.annotations.Type
annotation, like this:
@Column(name = "ACCOUNT_ID", nullable = false)
@Type(type = "org.hibernate.type.BinaryType")
private byte[] accountId;
Upvotes: 2