tags:

views:

1443

answers:

2

i have 2 tables table 1) cid jobtitle 2) pid jobspecif

i want that pid show be forign key in table1 can anyone provide me hibernate mappping for this

A: 

Since I don't know your data model all I can give you is this.

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

You should put this in the mapping file for the class that represents the first table. If you want to make it a bidirectional mapping you can put something like this in the mapping file for the second class.

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

you can also use annotation

@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;
Am1rr3zA