Hibernate 保存有许多关系,而无需添加到

Hibernate 保存有许多关系,而无需添加到,hibernate,grails,gorm,has-many,Hibernate,Grails,Gorm,Has Many,我们有两个域类 class FeeGroup { String name; static hasMany = [priceRanges:PriceRange] 及 从我的前端应用程序中,我收到了JSON格式的表单 { "name":"fee group 1", "priceRanges":[ {"from":10, "to":20, "include":true}, {"from":20, "t

我们有两个域类

class FeeGroup {

String name;

static hasMany = [priceRanges:PriceRange]

从我的前端应用程序中,我收到了JSON格式的表单

{
    "name":"fee group 1",
    "priceRanges":[
                    {"from":10, "to":20, "include":true},
                    {"from":20, "to":40, "include":true},
                    {"from":30, "to":60, "include":true}
                  ]
}
现在我想简单地保存所有数据

def model = new FeeGroup(data)
model.save()
使用此代码还应保存价格范围。这有什么问题?因为这只是一个团体!当你

println model.priceRanges
在model.save()之后,它还将打印PriceRanges的新ID,但数据库中没有任何内容,Hibernate中也没有任何内容(这里不帮助刷新)

文档中到处都是我应该使用model.AddToPriceRanges,但为什么呢?为什么一对一可以很好地工作而一对多不能

我已经尝试将FeeGroup域类更改为

class FeeGroup {

String name;
Set priceRanges
static hasMany = [priceRanges:PriceRange]
现在简单的保存工作非常完美,但是GORM创建了一个连接表fee\u group\u price\u range。。。我不想有3张桌子,因为有很多连接。这不是一个好的解决办法

谢谢你的建议

编辑

3表不是因为FeeGroup类的更改,而是因为将PriceRange类更改为

class PriceRange {

Integer from;
Integer to;
Boolean include;

static belongsTo = FeeGroup

希望能有所帮助。这是一个解决方案,但不好。。。更新是混乱的,因为您需要用新项目检查旧项目,比较哪些项目是新项目,哪些项目被更改,以及哪些项目在新项目中丢失(应该删除)。由于这个Grails错误,我们将项目移动到Java EE 7。您需要在JavaEE7中编写更多内容,但所有内容都能按预期工作。
class PriceRange {

Integer from;
Integer to;
Boolean include;

static belongsTo = FeeGroup