Thursday, August 27, 2009

Map boolean in Hibernate

How can you map Y/N in database as boolean in Java with Hibernate?

1. Java
private boolean trainingOnly;
// getters and setters

2. DB
training_only VARCHAR(1) DEFAULT 'N',

3. hbm.xml
<property name="trainingOnly" type="yes_no">
<column name="training_only" length="1" />
</property>

No comments:

Post a Comment