我如何映射这种关系?客户有许多以前的地址,但只有1个当前地址(双向关系) [英] How do I map this relationship? A customer had many previous address but only 1 current address (Bidirectional relationship)

查看:85
本文介绍了我如何映射这种关系?客户有许多以前的地址,但只有1个当前地址(双向关系)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



因此,在我的Oracle中,我将拥有以下表格:

  CUSTOMER 
CUSTOMER_ID
名称
CURRENT_ADDRESS

地址
ADDRESS_ID
CUSTOMER_ID
ADDRESS_DETAILS

我似乎无法将我的hibernate关系映射为能够设置它目前的地址,并有一个列表,以查找其以前的所有地址



我需要一个弱关系来表示它的当前地址吗?



  CURRENT_ADDRESS 
CUSTOMER_ID
ADDRESS_ID



我确定这是一个以前解决的常见问题。

解决方案


  1. 删除客户表中的current_address指针。


    1. 地址表中添加指标:IS_CURRENT。

    2. 创建一个只选择IS_CURRENT = TRUE地址的视图。

    3. 使用@OneToOne注释将此视图连接到 customer 的实体。


    您可以在问题



    希望它能帮助你:)

    A customer had many address but only one current address.

    Therefore in my Oracle I will have the following tables:

    CUSTOMER
    CUSTOMER_ID
    NAME
    CURRENT_ADDRESS
    
    ADDRESS
    ADDRESS_ID
    CUSTOMER_ID
    ADDRESS_DETAILS
    

    I can't seems to mapped out my hibernate relationship to be able to set its current address and have a list to find all its previous address

    Do I need a weak relationship to denotes it current address?

    ie

    CURRENT_ADDRESS
    CUSTOMER_ID
    ADDRESS_ID
    

    I'm sure this is a common issue that has been solved before.

    解决方案

    1. remove the current_address pointer in the customer table.

      1. add an indicator in the address table : IS_CURRENT.
      2. create a view that will select only the IS_CURRENT = TRUE addresses.
      3. connect this view to the customer's entity using @OneToOne annotation.

    you can find other solutions including mine in this question

    hope it helped you :)

    这篇关于我如何映射这种关系?客户有许多以前的地址,但只有1个当前地址(双向关系)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆