Home Hibernate Examples Hibernate Annotations Example

Ask Questions?

View Latest Questions


 
 

Hibernate Annotations Example
Posted on: October 27, 2010 at 12:00 AM
Advertisement
In this section we will see how we can develop Hibernate Annotations based example program.

Hibernate Annotations Example

In this section we will see how we can develop Hibernate Annotations based example program. After completing this tutorial you will be able to use Hibernate Annotations in your project and develop Hibernate based applications quickly.

With the introduction of Java 5 annotations with the release of Java 5, the development of Hibernate applications becomes much easier. Now Hibernate provides the Annotations support and you can take the full advantage of Annotations in your project.

If you Hibernate Annotations while developing the persistence layer for your application, the development process will be much easier. You can easily include the Mapping metadata into your persistence class. So, don't have to use the separate xml file as metadata.

 Here is the list of common Hibernate Annotations used in the applications.

  • @Entity - This annotation makes a class persistence class
  • @Table - The @Table annotations is used to map the persistence class to a table.
  • @Id - The primary key of the Entity.
  • @Column - The @Column annotation is used to map a java variable to table column.

Here an example of Entity class with Hibernate Annotations

@Entity
@Table(name = "employee")
public class Employee implements Serializable {
  public Employee() {

  }
  @Id
  @Column(name = "id")
  Integer id;

  @Column(name = "name")
  String name;

Read more at Quick Hibernate Annotation Tutorial and download the running code example.

Related Tags for Hibernate Annotations Example:


DMCA.com