我有一些相關的類。一個是有另一個類的對象集。像這樣,ElementCollection使用PlayFrameWork
@Entity
public class Serving extends Model{
@Required
public Item item;
@Required
public Float amount;
@Required
public Date time;
public Serving(Item item, Float amount) {
super();
this.item = item;
this.amount = amount;
this.time = new Date();
}
}
@Entity
public class Receipt extends Model{
@Required
@ElementCollection
@NotNull
public Set<Serving> servings;
@Required
DiningTable dtable;
public Receipt(Set<Serving> servings, DiningTable dtable) {
super();
this.servings = servings;
this.dtable = dtable;
}
//order'ın totalın hesaplamak lazım.
}
並且我也有一些yaml數據來初始化這個。
Serving(ser1): item : it1 amount : 1 time : 2012-04-05 12:10
Serving(ser2): item : it2 amount : 0.5 time : 2012-04-05 12:11
Serving(ser3): item : it3 amount : 2 time : 2012-04-04 13:10
Serving(ser4): item : it4 amount : 1 time : 2012-04-04 13:10
Serving(ser5): item : it5 amount : 0.5 time : 2012-04-04 14:00
Serving(ser6): item : it6 amount : 1 time : 2012-04-04 14:10
Serving(ser7): item : it7 amount : 1 time : 2012-04-03 16:00
Serving(ser8): item : it8 amount : 2 time : 2012-04-03 16:01
Serving(ser9): item : it9 amount : 1 time : 2012-04-03 16:30
Serving(ser10): item : it2 amount : 1 time : 2012-04-02 17:00
Receipt(rec1): dtable : tab1 servings :
- ser1 - ser2 - ser3Receipt(rec2): dtable : tab2 servings : - ser4 - ser5
Receipt(rec3): dtable : tab3 servings : - ser6
Receipt(rec4): dtable : tab4 servings : - ser7 - ser8
Receipt(5): dtable : tab4 servings : - ser9 - ser10
,當我試圖初始化此數據它給這個錯誤,
14:13:01,200 WARN ~ SQL Error: 1364, SQLState: HY000 14:13:01,200 ERROR ~ Field 'servings_time' doesn't have a default value 14:13:01,200 ERROR ~ Could not synchronize database state with session org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
我怎樣才能解決這個問題呢?
是在'ser2'服務複製 - 粘貼錯誤的逗號? – Codemwnci 2012-04-15 11:18:03
你是對的,這是我的錯。正確的是逗號或點? – 2012-04-15 11:38:17
點是正確的格式。 – Codemwnci 2012-04-15 11:43:01