Skip to main content

5.7 Object Mapping

dbVisitor maps Java entities to a database with @Table and @Column: an entity usually represents one row and its properties represent columns. A property can also be an entire object stored in one column; this is not a related-table or one-to-many relationship mapping.

Minimal Example​

import net.hasor.dbvisitor.mapping.Column;
import net.hasor.dbvisitor.mapping.Table;

@Table("users")
public class User {
@Column(primary = true)
private Integer id;

@Column("user_name")
private String name;

// Getters and setters omitted
}

User maps to the users table, id to the primary-key column and name to user_name. The table must already exist; declaring a mapping does not create it.

BaseMapper and LambdaTemplate entity mode use these mappings to generate CRUD statements. Executing native commands directly with JdbcTemplate does not require an entity.

Find Your Use Case​

What you needRead
Specify table and column names, or ignore propertiesMap a Table
Define mappings without annotating Java classesFile-Based Entity Mapping
Match names such as user_name and userNameCamel Case
Handle case-sensitive or keyword namesName Sensitivity
Control which properties participate in writesWrite Policy
Configure enums, abstract types and special conversionsType Mapping and Handlers
Store an object, Map or List as one JSON fieldJSON Field Mapping
Customize SQL expressions for column valuesStatement Templates
Configure auto-increment, sequence or UUID keysKey Generators