【问题标题】:grails hasOne but does not belong tograils hasOne 但不属于
【发布时间】:2015-01-22 13:21:17
【问题描述】:

我正在处理一个项目并且有一个当前为hasOne=[billingAddress:Address]Invoice 域类当我尝试启动我的服务器时,我收到以下错误:

hasOne property [Invoice.billingAddress] is not bidirectional. Specify the other side of the relationship!

虽然我不想分配关系的另一方...发票有一个帐单地址,但地址不属于发票。地址属于用户!!!

处理这种情况的正确方法是什么?

【问题讨论】:

  • 改用Address billingAddress

标签: hibernate grails grails-orm


【解决方案1】:

听起来你只需要一个正常的关联而不是hasOne

class Invoice {
  // other properties

  Address billingAddress
}

hasOne 机制是一种更改关联的数据库表示的方法,使用传统的Address billingAddress,您最终会在invoice 表中得到billing_address_id 列,而使用hasOne相反,关联由address 表中的外键表示 - 这种表示只允许每个Address 有一个Invoice,这就是关联必须是双向的原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 2019-07-05
    • 2010-12-24
    • 2014-07-17
    相关资源
    最近更新 更多