0
我使用OrmLite 5.0。我創建了2個實體,其中一個與另一個實體是一對一的關係。 這是我的回合類:OrmLite作爲外部文件的字段返回null,除了id字段
public class Round {
@DatabaseField(id = true)
private int id;
@DatabaseField(canBeNull = false)
private String name;
@DatabaseField(canBeNull = false, foreign = true, foreignAutoRefresh = true, foreignAutoCreate = true)
private Competition competition;
public Round(int id, String name, Competition competition) {
this.id = id;
this.name = name;
this.competition = competition;
}
public Round() {
}
,這是我的比賽類:
public class Competition {
@DatabaseField(id = true, columnName = "id", canBeNull = false)
private int id;
@DatabaseField(canBeNull = false)
private String name;
@DatabaseField(canBeNull = false)
private String flagUrl;
public Competition(int id, String name, String flagUrl) {
this.id = id;
this.name = name;
this.flagUrl = flagUrl;
}
public Competition() {
}
這是我ormlite_config.txt
# --table-start--
dataClass=com.example.test.model.db.Competition
tableName=competition
# --table-fields-start--
# --field-start--
fieldName=id
id=true
# --field-end--
# --field-start--
fieldName=name
# --field-end--
# --field-start--
fieldName=flagUrl
# --field-end--
# --table-fields-end--
# --table-end--
#################################
#################################
# --table-start--
dataClass=com.example.test.model.db.Round
tableName=round
# --table-fields-start--
# --field-start--
fieldName=id
id=true
# --field-end--
# --field-start--
fieldName=name
# --field-end--
# --field-start--
fieldName=competition
columnName=competition_id
foreign=true
# --field-end--
# --table-fields-end--
# --table-end--
#################################
我堅持比賽而圓。
回報
Competition[id=36, name='Champions League', flagUrl='https://static.crowdscores.com/flags/uefa.png'],
但
roundDAO.queryForAll();
回報
Round[id=1316, name="Group B", competition=Competition[id=36, name=null, flagUrl=null]]
我不知道如何從輪得到充分的競爭對象。