2012-04-03 3 views
2

내 모델을 작성하고 initial-data.yml을 통해 채우려 고 시도했습니다. 여기Play framework 2.0 Java - 모델 오류 및 initial-data.yml 정의

그것입니다

#Artists 

artists: 

    - !!models.Artist 
     id: 1 
     name: orelsan 
     occupation: chanteur 

#Records 
records: 
    - !!models.Record 
     id: 1 
     title: Le chant des sirenes 
     vinylType: La classe 
     pressInfo: a 
     style: rap 
     hits: 11 
     artist: !!models.Artist 
        id: 1 

그리고 다른 자바 파일 모델을 설명하는 : Record.java -

@Entity 
public class Record extends Model{ 

    @Id 
    public Long id; 

    @Required 
    public String title; 

    public String vinylType; 

    public String pressInfo; 

    public String style; 

    @ManyToOne 
    public Artist artist; 

    public int hits;//Number of time played-consulted 

    /** 
    * Generic query helper for entity record with id Long 
    */ 
    public static Finder<Long,Record> find = new Finder<Long, Record>(Long.class, Record.class); 
} 

Artist.java -

@Entity 
public class Artist extends Model{ 

    @Id 
    public Long id; 

    @Required 
    public String name; 

    @Required 
    public String occupation; 

    /** 
    * Generic query helper for entity Computer with id Long 
    */ 
    public static Finder<Long,Artist> find = new Finder<Long, Artist>(Long.class, Artist.class); 

    public String toString(){ 
     return name; 
    } 

} 

그리고 내 실행 앱에서 다음 예외를주지 :

play.api.UnexpectedException: Unexpected exception [PersistenceException: ERROR executing DML bindLog[] error[Referential integrity constraint violation: "FK_RECORD_ARTIST_1: PUBLIC.RECORD FOREIGN KEY(ARTIST_ID) REFERENCES PUBLIC.ARTIST(ID)"; SQL statement:\n insert into record (id, title, vinyl_type, press_info, style, hits, artist_id) values (?,?,?,?,?,?,?) [23506-158]]] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:134) ~[play_2.9.1.jar:2.0] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0] 
    at scala.Option.map(Option.scala:133) ~[scala-library.jar:0.11.2] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:112) ~[play_2.9.1.jar:2.0] 
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$3.apply(ApplicationProvider.scala:110) ~[play_2.9.1.jar:2.0] 
    at scala.Either$RightProjection.flatMap(Either.scala:277) ~[scala-library.jar:0.11.2] 
Caused by: javax.persistence.PersistenceException: ERROR executing DML bindLog[] error[Referential integrity constraint violation: "FK_RECORD_ARTIST_1: PUBLIC.RECORD FOREIGN KEY(ARTIST_ID) REFERENCES PUBLIC.ARTIST(ID)"; SQL statement:\n insert into record (id, title, vinyl_type, press_info, style, hits, artist_id) values (?,?,?,?,?,?,?) [23506-158]] 
    at com.avaje.ebeaninternal.server.persist.dml.DmlBeanPersister.execute(DmlBeanPersister.java:116) ~[ebean.jar:na] 
    at com.avaje.ebeaninternal.server.persist.dml.DmlBeanPersister.insert(DmlBeanPersister.java:76) ~[ebean.jar:na] 
    at com.avaje.ebeaninternal.server.persist.DefaultPersistExecute.executeInsertBean(DefaultPersistExecute.java:91) ~[ebean.jar:na] 
    at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeNow(PersistRequestBean.java:527) ~[ebean.jar:na] 
    at com.avaje.ebeaninternal.server.core.PersistRequestBean.executeOrQueue(PersistRequestBean.java:557) ~[ebean.jar:na] 
    at com.avaje.ebeaninternal.server.persist.DefaultPersister.insert(DefaultPersister.java:404) ~[ebean.jar:na] 
Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "FK_RECORD_ARTIST_1: PUBLIC.RECORD FOREIGN KEY(ARTIST_ID) REFERENCES PUBLIC.ARTIST(ID)"; SQL statement: 
insert into record (id, title, vinyl_type, press_info, style, hits, artist_id) values (?,?,?,?,?,?,?) [23506-158] 
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2.jar:1.3.158] 
    at org.h2.message.DbException.get(DbException.java:169) ~[h2.jar:1.3.158] 
    at org.h2.message.DbException.get(DbException.java:146) ~[h2.jar:1.3.158] 
    at org.h2.constraint.ConstraintReferential.checkRowOwnTable(ConstraintReferential.java:345) ~[h2.jar:1.3.158] 
    at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:287) ~[h2.jar:1.3.158] 
    at org.h2.table.Table.fireConstraints(Table.java:861) ~[h2.jar:1.3.158] 

나는 이것이 어디에서 유래하는지 정말로 이해하지 못한다. 기본적으로 ZenTask 샘플 코드를 기반으로합니다. 그것은 효과가 있지만.

아무도 아이디어가 있습니까?

감사

답변

0

당신이 Global.java의 Ebean.save에 대한 올바른 순서를 가지고 있는지 확인하십시오. 위의 예에서 기록하기 전에 아티스트를 저장하겠습니다.

관련 문제