Composition Vs Inheritance With JPA and Hibernate
Composition Vs Inheritance With JPA and Hibernate
www.thoughts-on-java.org
Composition vs. Inheritance with JPA and Hibernate
www.thoughts-on-java.org
Composition vs. Inheritance with JPA and Hibernate
the type of the associated entity or a collection of the associated
entities and a few annotation. I explained these mappings in great
details in one of my previous posts: Ultimate Guide – Association
Mappings with JPA and Hibernate.
...
}
After you have defined your embeddable, you can use it as the type of
an entity attribute. You just need to annotate it with @Embedded,
and your persistence provider will include the attributes and
mapping information of your embeddable in the entity. So, in this
www.thoughts-on-java.org
Composition vs. Inheritance with JPA and Hibernate
example, the attributes street, city and postalCode of the
embeddable Address will be mapped to columns with the same
names of the Author table.
@Entity
public class Author implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Embedded
private Address address;
...
}
www.thoughts-on-java.org
Composition vs. Inheritance with JPA and Hibernate
@Entity
public class Author implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Embedded
private Address privateAddress;
@Embedded
@AttributeOverride(
name = "street",
column = @Column( name = "business_street" )
)
@AttributeOverride(
name = "city",
column = @Column( name = "business_city" )
)
@AttributeOverride(
name = "postalCode",
column = @Column( name = "business_postcalcode" )
)
private Address businessAddress;
...
}
www.thoughts-on-java.org