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



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

Answer / 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

More Hibernate Interview Questions

What does service layer do?

1 Answers  


What is the difference between save and merge in hibernate?

1 Answers  


How does hibernate help in the programming?

1 Answers  


What are the mapping associations used in hibernate?

1 Answers  


How can we use new custom interfaces to enhance functionality of built-in interfaces of hibernate?

1 Answers  


Which is better spring jdbctemplate or hibernate for web development?

1 Answers  


What is query interface in hibernate?

1 Answers  


What is the difference between save() and persist() in hibernate?

1 Answers  


Do I need hibernate cfg xml?

1 Answers  


Tell about the core interfaces of the hibernate framework?

1 Answers  


What is the use of projection in hibernate?

1 Answers  


What is mapping class in hibernate?

1 Answers  


Categories