János János - 7 days ago 5
Java Question

Attribute without @DatabaseField?

Am I understanding well, if an attribute in data model is not annotated with

@DatabaseField
it will not persisted to DB?

@DatabaseField(columnName = "teacher_name")
public String teacherName;

Answer

an attribute in data model is not annotated with @DatabaseField it will not persisted to DB?

ORMLite needs to know which fields from your entity you want to be persisted to the database. It can do this a couple of different ways. The "standard" way is to use the @DatabaseField annotation. See setting up your classes.

@DatabaseField(columnName = "teacher_name")
public String teacherName;

You can also use the Javax @Column annotations as well.

@Column(name = "teacher_name")
public String teacherName;

The 3rd way you can configure your classes is through java code (or spring wiring). See class configuration documentation.

List<DatabaseFieldConfig> fieldConfigs = new ArrayList<>();
DatabaseFieldConfig field1 = new DatabaseFieldConfig("teacherName");
field1.setColumnName("teacher_name");
fieldConfigs.add(field1);
// add others if necessary ...
DatabaseTableConfig<Entity> tableConfig
    = new DatabaseTableConfig<Entity>(Entity.class, fieldConfigs);
Comments