2009-07-04 59 views

回答

0

因为我不知道你的数据模型,所有我可以给你的是这个。

<many-to-one name=„pid" 
    column="pid" 
    unique="true" 
    not-null=„true" /> 

你应该把它放在代表第一个表的类的映射文件中。如果你想使它成为一个双向映射,你可以在第二个类的映射文件中加入类似这样的内容。

<one-to-one name="name of the reference field for the first class in the second class" 
    property-ref="pid"/> 
1

你也可以使用注释

@Entity 
@Table(name = "jobtitle") 
public class jobtitle implements Serializable { 

    @Id 
    @Column(name = "cid ") 
    @GeneratedValue 
    private int cid ;  
    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) 
    @OnDelete(action=OnDeleteAction.CASCADE) 
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) 
    @JoinColumn(name = "jobspecif_fk", nullable=false) 
    private jobspecif jobspe; 


@Entity 
@Table(name = "jobspecif") 
public class jobspecif implements Serializable { 

    @Id 
    @GeneratedValue 
    private int pid; 
    @OneToOne(mappedBy = "jobspecif", fetch = FetchType.LAZY, cascade = CascadeType.ALL) 
    @OnDelete(action = OnDeleteAction.CASCADE) 
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN) 
    private jobtitle jobtit;