【问题标题】:Many-To-One relationship in YamlYaml 中的多对一关系
【发布时间】:2013-05-07 15:07:22
【问题描述】:

在我的 yaml 定义中,没有连接对象。它是空的。我没有看到问题:

人:

@Entity
@Table(name="person")
public class Person extends Model {

    @Id
    @Constraints.Required
    @Formats.NonEmpty
    public Long id;
...

生命周期事件:

@Entity
@Table(name="lifecycleevent")
public class LifeCycleEvent extends Model {

@Id
@Constraints.Required
@Formats.NonEmpty
public Integer id;

@ManyToOne
@Constraints.Required
public Person author;

初始化数据.yml

lifecycleevent:

- !!models.LifeCycleEvent
    title:      Lorem Away 1
    text:       Lorem ipsum dolor sit amet, consectetuer a ...
    read:       1
    creationDateTime:   2010-02-11 11:02:57
    publishingDateTime: 2012-01-12 07:30:00
    lastEditedDateTime: 2013-03-23 15:22:00
    author:     !!models.Person
                    id: 1

测试

    LifeCycleEvent lifeCycleEvent = LifeCycleEvent.findById(1);
    assertThat(lifeCycleEvent).isNotNull();
    assertThat(lifeCycleEvent.id).isEqualTo(1);
    assertThat(lifeCycleEvent.author).overridingErrorMessage("Author of " + lifeCycleEvent + " can not be null").isNotNull();

【问题讨论】:

  • 你实际在哪里加载 yaml 数据并将其插入数据库?
  • 在全局设置中如播放示例所示。这两个实体存在。我检查了

标签: jpa playframework persistence yaml playframework-2.1


【解决方案1】:

问题在于(当然)全局设置中 Ebean.save() 的顺序很重要

【讨论】:

    猜你喜欢
    • 2011-03-10
    • 2014-02-13
    • 2011-02-17
    • 1970-01-01
    • 2018-06-15
    • 2018-09-27
    • 2011-03-30
    • 2023-01-16
    • 2015-09-20
    相关资源
    最近更新 更多