Hibernate @Entity

We can create a Persistent class using @Entity annotation.
Following are some of the important annotations used in a persistent class and their description.

Annotation
Description
@Entity
This annotation is used to make a hibernate class a Persistent entity.
@Id
This annotation is used to mark the primary key of the Entity.
@GeneratedValue
This annotation is used to indicate that the value is auto generated.

Let us create a persistent class Planet as shown below.
package com.cosmiclearn.model;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;


@Entity
class Planet
{
	@Id
	@GeneratedValue
	private Long planetId;

	private String name;
	private Integer numberOfMoons;

	public String getName()
	{
		return this.name;
	}

	public String setName(String name)
	{
		this.name = name;
	}

	public Integer getNumberOfMoons()
	{
		return this.numberOfMoons;
	}

	public String setNumberOfMoons(Integer numberOfMoons)
	{
		this.numberOfMoons = numberOfMoons;
	}
}

Previous: persistence.xml | Next: @OneToMany

<
>