Hibernate Annotations
Hibernate Annotations
****Annotations
-starts with @symbol
-used to hold metadata along with the java code & so must be used for fixed stuff
-Annotations are inside the java code [not external like xml] & so if changed java
code needs to rebuild
**use
DB COnfigurations will keep on changing -[hibernate.cfg.xml]
Table structure remain same-[use annotation]
__________________________________________________________
Annotations
@Entity--->marks a class as a Entity/POJO class
@Table-->specific table name
@Id--->specific PK column
@Column--->specify non PK columns
___________________________________________________
steps for Hibernate-Annotation
1)open eclipse
2)create java project & add hibernate+db jar files
__________________________________________________________
****Component Mapping
How to map has a kind of Class relationship[Containment]
@Entity @Table
class Employee{
@Id,@Column
empid
@Column
empname,empsal,jdate;
@Embedded
Address ob;
}
@Embeddable
class Address{
@Column
street,city,country,pincode;
}
//Here do not create a seperate table for class Address
_________________________________________________________________________
Lab2)
Profile [Main POJO]
--------
int profileId
Date creationDate
PersonalDetails perInfo
EducationalDetails eduInfo
PersonalDetails
----------------
String firstName,lastName,email,contactNo,gender
Date birthDate
Address resAddr
Address
-------
String street,city,country,zip
EducationalDetails
------------------
String qualification,result
int yearPassing
__________________________________________________
__________________________________________________