Hibernate Annotation
Hibernate 3.1 offers a variety of additional annotations that you can mix/match with your EJB 3 entities. They have been designed as a natural extension of EJB3 annotations. To empower the EJB3 capabilities, hibernate provides specific annotations that match hibernate features. The org.hibernate.annotations package contains all these annotations extensions.
- @Entity :- @org.hibernate.annotations.Entity
- @Id
- @GeneratedValue
- @Formula
- @Type
- @Column
- @Index
- @Parent
- @Target
- @ForeignKey
- @ManyToOne
- @OneToMany
- @JoinColumn
- @Sort
- @Where
- @OnDelete
- @ManyToMany
- @OrderColumn
- @JoinTable
- @CollectionId
- @ManyToAny
- @FilterDef
- @Filters
- @SQLInsert
- @SQLUpdate
- @SQLDelete
- @SQLDeleteAll
- @Loader
- @NamedNativeQuery
- @SecondaryTables
- @Tuplizer
Employee.java
package com.javaskool;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name="emp")
public class Employee {
@Id
@Column(name="empid")
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer empid;
@Column(name="emp_name")
private String ename;
@Column
private String eadd;
@Column
@Transient
private String email;
@Column
private Integer salary;
public Integer getEmpid() {
return empid;
}
//.....more code
}
Hibernate Annotation Project Hierarchy

Employee.java With Hibernate Annotation

Hibernate Configuration File : hibernate.cfg.xml

TestDrive.java for Hibernate Annotation Application

Output
mysql> select * from emp;
+-------+------------+----------+--------+
| empid | eadd | emp_name | salary |
+-------+------------+----------+--------+
| 1 | California | Tom | 4600 |
+-------+------------+----------+--------+
1 row in set (0.37 sec)
Click the below Link to download complete Example
Recent Comments