| The last SqlAnywhere's documentation is here: http://dcx.sap.com/index.html or https://help.sap.com/viewer/product/SAP_SQL_Anywhere/17.0/en-US the documentation says: "BIT is an integer type that can store the values 0 or 1. By default, the BIT data type does not allow NULL. A BIT value requires 1 byte of storage." Idem for sql anywhere version 10. If I execute this statement: CREATE TABLE "dbm"."mytable" ( "id" BIGINT NOT NULL, "bitfield" BIT, "tinyintfield" TINYINT, PRIMARY KEY ( "id" ASC ) ) IN "system"; the bit field not allows null, the tinyint field allows null. if I execute this statement: CREATE TABLE "dbm"."mytable" ( "id" BIGINT NOT NULL, "bitfield" BIT NULL, "tinyintfield" TINYINT NULL, PRIMARY KEY ( "id" ASC ) ) IN "system"; the bit field and the tinyint field allow null. This is the meaning of "By default, the BIT data type does not allow NULL", if I omit NULL directive on field declaration, by default it is NOT NULL Importing this last table with hibernate tools I get this entity:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* Mytable generated by hbm2java
*/
@Entity
@Table(name = "mytable", schema = "dbm")
public class Mytable implements java.io.Serializable {
private long id;
private Boolean bitfield;
private Byte tinyintfield;
public Mytable() {
}
public Mytable(long id) {
this.id = id;
}
public Mytable(long id, Boolean bitfield, Byte tinyintfield) {
this.id = id;
this.bitfield = bitfield;
this.tinyintfield = tinyintfield;
}
@Id
@Column(name = "id", nullable = false)
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
@Column(name = "bitfield")
public Boolean getBitfield() {
return this.bitfield;
}
public void setBitfield(Boolean bitfield) {
this.bitfield = bitfield;
}
@Column(name = "tinyintfield")
public Byte getTinyintfield() {
return this.tinyintfield;
}
public void setTinyintfield(Byte tinyintfield) {
this.tinyintfield = tinyintfield;
}
}
inserting record with null value for Boolean field in my old version of hibernate (5.0.12) in the code:
public SqlTypeDescriptor remapSqlTypeDescriptor(SqlTypeDescriptor sqlTypeDescriptor) {
if ( sqlTypeDescriptor == null ) {
throw new IllegalArgumentException( "sqlTypeDescriptor is null" );
}
if ( ! sqlTypeDescriptor.canBeRemapped() ) {
return sqlTypeDescriptor;
}
final SqlTypeDescriptor overridden = getSqlTypeDescriptorOverride( sqlTypeDescriptor.getSqlType() );
return overridden == null ? sqlTypeDescriptor : overridden;
}
overridden is null and sqlTypeDescriptor remain Types.BOOLEAN = 16 We can map BOOLEAN to "bit" in SybaseAnywhereDialect (bit type can allow null) |