gpt4 book ai didi

postgresql - 域验证但不会保存

转载 作者:行者123 更新时间:2023-11-29 13:06:27 25 4
gpt4 key购买 nike

我有以下设置。

类,例如,具有 CarPart (belongsTo=[car:Car]) 的 Car。

当我创建汽车时,我还想创建一些默认的 CarPart,所以我这样做了

def car = new Car(bla bla bla)
def part = new CarPart(car:car)

现在,当我执行 car.validate() 或 part.validate() 时,它看起来很好。但是当我做 if(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)

有什么想法吗?

最佳答案

调用验证实际上只会检查约束。保存失败的是对数据库的实际持久性(验证无法真正检查)。

通常,在 Grails 中,您会希望使用以下 2 种方式中的一种:

def car = new Car(bla bla)
car.save()
def carPart = new CarPart(car:car)
carPart.save()

def car = new Car(bla bla)
def carPart = new CarPart(bla bla)
car.addToCarParts(carPart)
car.save()

关于postgresql - 域验证但不会保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9852030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com