我正在嘗試從yaml文件加載模型。內容是:從YAML文件加載模型數據
#test data
User(marchaos):
username: marchaos
email: [email protected]
passwordHash: cf6dd541822b1b3d2d23c92adda75211
模型看起來像這樣。
@Entity
public class User extends Model
{
@Unique
@Required
private final String username;
@Email
@Required
private final String email;
@Required
private final String passwordHash;
public User(String username, String email, String password)
{
this.username = username;
this.email = email;
//TODO: salt
this.passwordHash = Codec.hexMD5(password);
}
public String getUsername()
{
return username;
}
public String getEmail()
{
return email;
}
}
的YAML文件被加載在Bootstrap類:
Fixtures.loadModels("User.yml");
用戶看起來像是被創建,但所有的字段爲空:
System.out.println(((User) User.all().first()).getUsername());
// prints null
知道爲什麼會有沒有數據的用戶?如果我使用構造函數創建用戶,則存在用戶數據。
我知道md5問題(因此鹽評論)。當我使用標籤時出現錯誤,所以不是這樣。任何其他想法可能是什麼? – marchaos 2012-01-01 19:17:50
將我的密碼字段設置爲私人後,就像一個魅力工作,然後yaml不得不使用setter。 – nbz 2015-03-16 16:35:09