Composition vs. Inheritance with JPA and Hibernate
|

Composition vs. Inheritance with JPA and Hibernate

Like all object-oriented programing languages, Java supports the fundamental concepts of inheritance and composition. There is an important difference between both concepts. Inheritance enables you to model an is-a association between two classes by extending a superclass. Composition models a has-a association by referencing another class in an instance variable. You can use both concepts…

Best Practices for Many-To-One and One-To-Many Association Mappings
|

Best Practices for Many-To-One and One-To-Many Association Mappings

When you model your database, you will most likely define several many-to-one or one-to-many associations. And it’s, of course, the same when you model your entities. It’s quite easy to do that with JPA and Hibernate. You just need an attribute that represents the association and annotate it with a @ManyToOne or @OneToMany association. But…