I have some classes which are related. One them is have another classes’s object set. Like this,
@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.
}
and i also have some yaml data to initalize this.
Serving(ser1):
item : it1
amount : 1
time : 2012-04-05 12:10Serving(ser2):
item : it2
amount : 0.5
time : 2012-04-05 12:11Serving(ser3):
item : it3
amount : 2
time : 2012-04-04 13:10Serving(ser4):
item : it4
amount : 1
time : 2012-04-04 13:10Serving(ser5):
item : it5
amount : 0.5
time : 2012-04-04 14:00Serving(ser6):
item : it6
amount : 1
time : 2012-04-04 14:10Serving(ser7):
item : it7
amount : 1
time : 2012-04-03 16:00Serving(ser8):
item : it8
amount : 2
time : 2012-04-03 16:01Serving(ser9):
item : it9
amount : 1
time : 2012-04-03 16:30Serving(ser10):
item : it2
amount : 1
time : 2012-04-02 17:00Receipt(rec1):
dtable : tab1
servings :
– ser1
– ser2
– ser3Receipt(rec2):
dtable : tab2
servings :
– ser4
– ser5Receipt(rec3):
dtable : tab3
servings :
– ser6Receipt(rec4):
dtable : tab4
servings :
– ser7
– ser8Receipt(5):
dtable : tab4
servings :
– ser9
– ser10
When i tried to initialize this data it gives this error,
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
How can i resolve this problem?
In serving class constructor must be get date as parameter.
So i have to add this constructor too…