2017-05-07 20 views
0

OrmLite 5.0を使用しています。私は2つのエンティティを作成しました.1つは1対1で別のエンティティと関連しています。 これは私のラウンドクラスです:OrmLiteは、foreign filedsのフィールドとして、nullを返します。

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]] 

私は丸いから、完全な競争のオブジェクトを取得する方法は考えています。

答えて

0

私の場合はこの問題を解決しました。 私のコードは次のとおりです。

@DatabaseTable(tableName = "tbl_turn_list") 
public class TurnListItem { 
    @DatabaseField(generatedId = true, index = true) 
    public int id; 
    @DatabaseField(defaultValue = "false") 
    public Boolean is_sent; 
    @DatabaseField(foreignAutoRefresh = true,foreign = true, columnName = "related_driver_id") 
    public Driver related_driver; 

    public TurnListItem() { 
    } 
} 

が、私はこのクラスのオブジェクトに対してクエリを実行するとき「真foreignAutoRefresh = whithout」私が受け取ったオブジェクトが初期化だけでidを持つ異物ドライバを持っています。 「whithout foreignAutoRefresh = true」を追加したとき、異物はIDを含むすべてのファイルIDを埋めました。 「foreignAutoCreate = true」を削除しても問題が解決する場合があります。

関連する問題