1
我有以下设置。域验证,但不会保存
类,例如,有CarPart(belongsTo = [car:Car])的汽车。
当我创建一个租车我也想创建索姆默认CarParts,所以我做
def car = new Car(bla bla bla)
def part = new CarPart(car:car)
现在,当我做car.validate()或part.validate()似乎罚款。 但是当我做,如果(car.save & & part.save()我得到这个异常:?
2012-03-24 14:02:21,943 [http-8080-4] ERROR util.JDBCExceptionReporter - Batch entry 0 insert into car_part (version, car_id, id) values ('0', '297', '298') was aborted. Call getNextException to see the cause.
2012-03-24 14:02:21,943 [http-8080-4] ERROR util.JDBCExceptionReporter - ERROR: value too long for type character varying(6)
2012-03-24 14:02:21,943 [http-8080-4] ERROR events.PatchedDefaultFlushEventListener - Could not synchronize database state with session
org.hibernate.exception.DataException: Could not execute JDBC batch update
Stacktrace follows:
java.sql.BatchUpdateException: Batch entry 0 insert into car_part (version, deal_id, id) values ('0', '297', '298') was aborted. Call getNextException to see the cause.
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2621)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1837)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2754)
at $Proxy20.flush(Unknown Source)
at ristretto.DealController$_closure5.doCall(DealController.groovy:109)
at ristretto.DealController$_closure5.doCall(DealController.groovy)
at java.lang.Thread.run(Thread.java:722)
任何想法
很好的回答,但我真的想用某种类型的交易要做到这一点,如果由于某种原因,CarPart不保存任何一方都不应该在车... – marko 2012-03-25 13:57:28
所以把它放在一个服务和交易将得到处理。如果是这种情况,我的第二个例子会更好。如果CarPart失败,错误将持续到Car并且事务将被回滚。 – Gregg 2012-03-26 03:14:57
我试着在服务中做到这一点,我得到我的车(已经创建),并做CarPart p = new CarPart(bla bla bla).save(),它给我:java.sql.BatchUpdateException:批次条目0插入('0','2012-03-26 23:11:01.512000 +02:00:00','303','SHAFT','368')的car_part(version,created,car_id,status,id)被中止。调用getNextException来查看原因。 \t at org.postgresql.jdbc2.AbstractJdbc2Statement $ BatchResultHandler.handleError(AbstractJdbc2Statement.java:2621) – marko 2012-03-27 07:12:54