2013-05-07 85 views
1

在我的yaml定義中,對象沒有連接。它是空的。我不明白的問題:Yaml中的多對一關係

人:

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

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

LifeCycleEvent:

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

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

@ManyToOne 
@Constraints.Required 
public Person author; 

的init-data.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(); 
+0

你究竟在哪裏加載yaml數據並將其插入數據庫?如全球設置中的 – 2013-05-07 21:23:11

+0

所示。這兩個實體存在。我檢查了 – myborobudur 2013-05-08 06:03:12

回答

1

問題是(當然)Ebean.save()在全局設置中的順序很重要