adspace


How do you implement one to one relationship in hibernate with java annotation?

Answer Posted / Divya Bansal

One-to-one relationships can be implemented using the @OneToOne and @JoinColumn annotations. Here's an example:nn@Entitynpublic class Invoice {n @Idn private Long id;nn @OneToOnen @JoinColumn(name = "invoice_id", referencedColumnName = "id")n private Payment payment;nn // constructors, getters and setters...}nn@Entitynpublic class Payment {n @Idn private Long id;nn // constructors, getters and setters...

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is latest hibernate version?

493