2012-04-03 7 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 

とモデルを記述する別のJavaファイル: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のための正しい順序を持っていることを確認してください。上記の例から、レコードを保存する前にアーティストを保存すると思います

関連する問題