【问题标题】:YAML mock data references to entities not working对实体的 YAML 模拟数据引用不起作用
【发布时间】:2012-02-25 03:17:29
【问题描述】:

我的 Play Framework 项目中有以下 mockdata.yml 文件:

Account(cash):
  name: Cash
  type: CASH
  balance: 1015

Category(food):
  name: Food
  type: DISCRETIONARY_EXPENSE
  monthlyBudget: 200

Transaction(txn0001):
  account: cash
  category: food
  date: 2012-02-24
  amount: 12

我在我的应用程序启动时加载了这个模拟数据,我可以看到我的数据库中的所有可用记录。但是,Transaction 记录的account 和category 列中有null。

我的格式似乎与here 显示的示例匹配,但从Transaction 到Account 和Category 的实体引用不起作用。

可能出了什么问题?

作为参考,这里是我的模型对象:

@Entity
public class Account extends Model
{
    public String name;
    public AccountType type;
    public long balance;
}

@Entity
public class Category extends Model
{
    public String name;
    public CategoryType type;
    public long monthlyBudget;
}

@Entity
public class Transaction extends Model
{
    public Account account;
    public Category category;
    public Date date;
    public long amount;
}

(AccountType 和 CategoryType 是枚举。)

【问题讨论】:

    标签: playframework yaml


    【解决方案1】:

    啊!一旦我发布了我的模型类,我就看到了问题。 (发生这种情况时会喜欢它!)

    对于遇到相同问题的其他人,这里是解决方案:Transaction 类的 Account 和 Category 字段需要 @ManyToOne 注释。我一添加它们,它就开始按预期工作。

    @Entity
    public class Transaction extends Model
    {
        @ManyToOne public Account account;
        @ManyToOne public Category category;
        public Date date;
        public long amount;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 2019-11-20
      • 2014-06-19
      相关资源
      最近更新 更多