Hint
This article is generated by AI translation.
Type Mapping and Handlers
When a Java int maps to a database int, three aspects matter:
- ➊ Java type used by the property
- ➋ JDBC type of the column
- ➌ TypeHandler for reading/writing
@Table
public class Users {
@Column(➋ jdbcType = java.sql.Types.TINYINT, ➌ typeHandler = IntegerTypeHandler.class)
private ➊ Integer id;
}
info
In most cases you can ignore jdbcType and typeHandler; the framework selects them from the Java type.
Handle abstract types
@Table
public class Users {
@Column(specialJavaType = Integer.class)
private Number counter;
}
Handle enums
@Table
public class Users {
@Column
private UserTypeEnum type; // Automatically supported; no extra work
}
- For more on enum mapping, see Enum type handler.
Handle JSON serialization
Bind JSON serializer via @Column
@Table
public class Users {
@Column(typeHandler = net.hasor.dbvisitor.types.handler.json.JsonTypeHandler.class)
private UserExtInfo moreInfo; // Field is serialized/deserialized as JSON
}
Set serializer for a type via @BindTypeHandler
@BindTypeHandler(net.hasor.dbvisitor.types.handler.json.JsonTypeHandler.class)
public class UserExtInfo {
...
}
@Table
public class Users {
private UserExtInfo moreInfo;
}
Use a custom TypeHandler
public class User {
@Column(typeHandler = MyDateTypeHandler.class)
private String myTime;
}
- See Custom TypeHandler for more details.