How to set boolean value in hibernate?
This is the bean,
public boolean paid;
public boolean isPaid()
{
return paid;
}
public void setPaid(boolean paid)
{
this.paid=paid;
}
But when i create an object to save in database开发者_JS百科 like,
CourseFee fee=new CourseFee(); fee.setPaid(false); hibernateTemplate.save(fee);
I get the following exception,
java.sql.BatchUpdateException: Data too long for column 'paid' at row 1
Which is the correct way to set boolean values in hibernate?
I use this way.
@Column(name="isAdmin", columnDefinition = "tinyint default false")
public boolean isAdmin() {
return admin;
}
I do not succeed in using default value. It compiles but default value is never used.
I followed following steps :
put on Class declaration
@DynamicInsert @DynamicUpdate
put on property
@Column( nullable = false, columnDefinition = "BOOLEAN DEFAULT false" ) )
or Add boolean option as a bit
@Column ( precision = 1, scale = 0, nullable = false, columnDefinition = "bit default 1" )
Reference : http://www.mkyong.com/hibernate/hibernate-dynamic-insert-attribute-example/
Try using big Boolean
in your POJO class.
Or try updating your mapping like this:
<property name="paid" not-null="true" >
<column sql-type="BOOLEAN" not-null="true" name="paid" />
</property>
Thanks.
精彩评论