我有一些相关的类。一个是有另一个类的对象集。像这样,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