2009-07-04 93 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;