Reputation: 7282
I'm developing a Bet service with Java and MySql using Spring and Hibernate, but I have a question about a mapping:
In my database I have bet types
(questions) like: ¿Who will win the match? and bet options
for each type like: 1, X, 2. Each option has a boolean indicator to show if an option is a winner option or not. So, the mapping in MySql for this attribute is a boolean like this: 1
if the option is winner, 0
if the option is looser, and null
if the option is not yet neither winner or looser
So, in my service layer, how can I check if the winner attribute in an option is null? I've tried option.getIsWinner() != null
but boolean is a primitive type so it can be null. Any idea on this?
Thanks.
Upvotes: 0
Views: 1439
Reputation: 1840
Java has two boolean types; lowercase-b boolean
, which is a primitive, and one is capital-B Boolean
, which is an object. The object variant can also be null, so it should be possible for it to be null in the event that the database column is null. If you switch over to java.lang.Boolean
you should get the behavior you expect. I just looked in the Hibernate docs, and it supports both.
Upvotes: 1