Hibernate GORM&x2B;休眠:仅插入外键

Hibernate GORM&x2B;休眠:仅插入外键,hibernate,grails,orm,mapping,gorm,Hibernate,Grails,Orm,Mapping,Gorm,我有这样一个域实体: class MyEntity{ AnotherEntity anotherEntity static mapping{ anotherEntity column: 'ANOTHER_ENTITY_ID', ignoreNotFound: true } } class AnotherEntity{ long AnotherEntityId string SomethingElse } 当我保存MyEntity的实例

我有这样一个域实体:

class MyEntity{
    AnotherEntity anotherEntity

    static mapping{
        anotherEntity column: 'ANOTHER_ENTITY_ID', ignoreNotFound: true
    }
}

class AnotherEntity{
    long AnotherEntityId
    string SomethingElse
}

当我保存
MyEntity
的实例时,我还希望在MyEntity的表中持久化
anotherity
的外键,而不必经过anotherty的验证或持久化。如果我将其映射为
insertable:false
,则不会有任何结果。

您完全可以只使用id,而不使用实体
MyEntity
应该将
Long anotherEntityId
映射到相应的列,而不是
anotherEntity
。这样,您就绕过了实体验证和持久性。@dmahapatro我已经尝试过了,并且在大多数情况下都有效。然而,我想知道这是否可以避免。