gpt4 book ai didi

hibernate - Grails将多对一从设置更改为列表(列需要更改)

转载 作者:行者123 更新时间:2023-12-02 14:02:46 25 4
gpt4 key购买 nike

在Grails域对象中,我试图更改域对象

class Example {
String name

static hasMany = [objs:DomainObject]
}


class Example {
String name
List objs

static hasMany = [objs:DomainObject]
}

我得到这个错误。
ERROR errors.GrailsExceptionResolver  - HibernateException occurred when processing request: [GET] /path/path
null index column for collection: com.XXXX. Stacktrace follows:
org.hibernate.HibernateException: null index column for collection: com.XXXXXX
at grails.converters.JSON.value(JSON.java:174)
at grails.converters.JSON.convertAnother(JSON.java:162)
at grails.converters.JSON.value(JSON.java:199)
at grails.converters.JSON.convertAnother(JSON.java:162)
at grails.converters.JSON.value(JSON.java:199)
at grails.converters.JSON.convertAnother(JSON.java:162)
at grails.converters.JSON.value(JSON.java:199)
at grails.converters.JSON.convertAnother(JSON.java:162)
at grails.converters.JSON.value(JSON.java:199)
at grails.converters.JSON.render(JSON.java:134)
at grails.converters.JSON.render(JSON.java:150)
at com.XXXXController.Method(XXXXController.groovy:161)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)`

这在生产服务器上发生。我无法从数据库中删除任何内容,但可以填写空白列。我需要在可修复或更改当前数据库中数据的 bootstrap 中做什么?

最佳答案

看一下这篇文章。它描述了如何在新的idx列中放置随机顺序。

http://tech.coterie.com/2012/11/migrating-from-set-to-list-in-grails.html

这是文章中提供的示例SQL:

insert into user_product(user_products_id, product_id, products_idx)
select t.user_id, t.product_id, (@rownum:=@rownum+1) % c.loves AS idx
from (
select user_id, product_id
from love_link
order by user_id
) t,
(
select user_id, count(*) as loves
from love_link
group by user_id
) c,
(SELECT @rownum:=0) r
where c.user_id=t.user_id
order by t.user_id;

关于hibernate - Grails将多对一从设置更改为列表(列需要更改),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16906999/

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