Я пытался построить свою собственную модель и заполнить ее с помощью 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. Хотя это будет работать.
У кого-нибудь есть идея?
Спасибо