Hibernate 如何创建包含其他列的联接表

Hibernate 如何创建包含其他列的联接表,hibernate,hibernate-annotations,Hibernate,Hibernate Annotations,我有一个用户表和一个联系人表。我想做的是创建一个联接表,允许我将单个用户联接到3个联系人-家庭地址、账单地址和发货地址 目前,我在用户和用户_地址之间有一对一的映射,然后在用户_地址和每个不同的地址类型之间有一对一的映射 我已经和多对多的专栏玩过了,一对多,但到目前为止还并没有成功 除了我这样做的方式,还有其他选择吗 一对一映射: User.java /** * Relationship to the User Address - extension of User */

我有一个用户表和一个联系人表。我想做的是创建一个联接表,允许我将单个用户联接到3个联系人-家庭地址、账单地址和发货地址

目前,我在用户和用户_地址之间有一对一的映射,然后在用户_地址和每个不同的地址类型之间有一对一的映射

我已经和多对多的专栏玩过了,一对多,但到目前为止还并没有成功

除了我这样做的方式,还有其他选择吗

一对一映射:

User.java


  /**
   * Relationship to the User Address - extension of User
   */
  @OneToOne(cascade = CascadeType.ALL, mappedBy = "user",fetch=FetchType.EAGER)
  private UserAddress userAddress;


没有“使用额外列连接表”这样的东西。如果存在与连接无关的列,那么它本身就是一个实体,应该这样对待它。你目前的策略是最好的。对此感到高兴:-)

    UserAddress.java


    @Entity
    @Table(name = "a_user_address")
    @GenericGenerator(name = "user-primarykey", strategy = "foreign", parameters = @Parameter(name = "property", value = "user"))
    @Audited
    public class UserAddress extends Trackable implements Serializable
    {
        /**
         * The unique identifier associated with the user. References user(id).
         */
        @Id
        @GeneratedValue(generator = "user-primarykey")
        @Column(name = "user_id", unique = true, nullable = false)
        private Long userId;

        /**
         * 
         */
        @OneToOne
        @PrimaryKeyJoinColumn
        private User user;

    /**
     * The unique identifier associated with the user's home/profile address
     */
  @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
  @JoinColumn(name="home_addr_id", nullable=true, updatable=true)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private ContactInfo homeAddress;

    /**
     * The unique identifier associated with the user's billing address
     */
  @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
  @JoinColumn(name="billing_addr_id", nullable=true, updatable=true)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private ContactInfo billingAddress;

    /**
     * The unique identifier associated with the user's shipping address
     */
  @OneToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
  @JoinColumn(name="shipping_addr_id", nullable=true, updatable=true)
  @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private ContactInfo shippingAddress;