Hibernate OneToOne mapping primary key [Annotation]

<1>Annotation Methods Settings

@Entity
@Table("t_husband")
public class Husband{
    private int id;
    private String name;
    private Wife wife;

    /*
    * get set ...
    */

    @Id
    @GeneratedValue
    public int getId(){
 return id;
    }
   
    @OneToOne
    public Wife getWife(){
        return wife;
    }
}


@Entity
@Table(name="t_wife")
public class Wife{
    private int id;
    private String name;
   
    @Id
    @GeneratedValue
    public int getId(){
 return id;
    }
}

你可能感兴趣的:(Hibernate,框架,职场,映射,休闲)