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 |
What does service layer do?
What is the difference between save and merge in hibernate?
How does hibernate help in the programming?
What are the mapping associations used in hibernate?
How can we use new custom interfaces to enhance functionality of built-in interfaces of hibernate?
Which is better spring jdbctemplate or hibernate for web development?
What is query interface in hibernate?
What is the difference between save() and persist() in hibernate?
Do I need hibernate cfg xml?
Tell about the core interfaces of the hibernate framework?
What is the use of projection in hibernate?
What is mapping class in hibernate?