Lesson - 67 : Hibernate - Component mapping using XML and Annotation based Config

Lesson - 67 : Hibernate - Component mapping using XML and Annotation based Config

Sada Learning Hub

55 лет назад

535 Просмотров

Hibernate – Component Mapping in Hibernate Using XML Configuration :
In java the properties of one class can be used in another class two ways
1. By inheriting one class from another class.
2. By creating an object of one class in another class.
-> The first way is is-a relationship and second way is has-a relationship.
-> If we want to use properties of one class in another class for more than once then we use has-a relationship.
-> The has-a relationship is mapped in hibernate using component mapping.
-> For example a student can have two addresses like temporary and permanent. It means we need address properties for twice for a student. So we apply has-a relation between a student and address.
-> In hbm file has-a relationship can be configured using component mapping. To do component mapping the tag is <component>

Configuration :
<hibernate-mapping>
<class name="com.sada.Model.Student" table="STUDENTS">
---
<component name="address">
<property name="hno"/>
<property name="street"/>
<property name="city"/>
</component>
</class>
</hibernate-mapping>

Hibernate – Component Mapping in Hibernate Using Annotations :
-> When we want to use properties of one class in another class more than once then we apply component mapping.
-> To make a class as a component for other classes we use @Embeddable annotation.
-> To insert a component class reference into another class. We use @Embedded annotation.
-> In the following example a class pname is acting as a component class for a class person.
-> To make pname class as a component class we use @Embeddableand to insert its objet into person class we used @Embedded

Configuration :
@Entity
@Table(name="person")
public class Person {
---
@Embedded
private Pname pname;
---
}

@Embeddable
public class Pname {
}

Hibernate Examples Project Github Link : https://github.com/SadaLearningHub1/Hibernate-Projects

Тэги:

#hibernate_interview_questions #hibernate_tutorials #hibernate_architecture #hibernate_mapping #hibernate_annotations #hibernate_configuration #hibernate_criteria #hibernate_classes #hibernate_cascade #hibernate_crud #hibernate_collection_mapping #hibernate_envers #hibernate_framework #hibernate_generator_class #hibernate_hql #hibernate_life_cycle #hibernate_native_sql #hibernate_object_states #hibernate_one_to_many #hibernate_query_language_tutorial #hibernate_relationships
Ссылки и html тэги не поддерживаются


Комментарии: