Hibernate Annotations


Hibernate Annotations Study

This example is the same as the first example, except that we use annotations where we started by creating a file.

In addition to the existing pot files, you need to add the following jar files to the classpath.

hibernate-commons-annotations.jar
ejb3-persistence.jar
hibernate adjectives.jar
Here we begin by creating a Course section. The course category is shown below.

package com.vaannila.course;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table (name = "COURSES")
Social study

    long secret course
    Private String courseName;

         Public course () {
    }

         String courseName {
    this.courseName = courseName;
    }

         @Id
    @GeneratedValue
    @Column (name = "COURSE_ID")
    public long GetCourseId () {
    replace this.courseId;
    }

         public gap setCourseId (long courseId course)
    this.courseId = courseId;
    }

         @Column (name = "COURSE_NAME", nullable = false)
    public String getCourseName () {
   replace this.courseName;
    }

         public void setCourseName (String courseName) {
    this.courseName = courseName;
    }
}

The @Entity annotation is used to mark this category as Business Beans, and the class should at least have a non-controversial package builder.

The @Table annotation is used to specify a table to access data. Word adjective means a table name. If the @Table annotation is not specified, Hibernate will automatically use the category name as the table name.

The @Id annotation is used to specify a business bean identification asset. If the @Id annotation is located above the field, input access will be used. Instead, if you override the acquisition field, access to the property will be used. Here we use asset access.

The @GeneratedValue annotation is used to specify a key creation strategy to be used. If the method is not selected automatically, AUTO will be used.

The @Column annotation is used to specify the details of the column in which the field or property will be mapped. Here the course is marked in the COURSE_ID column in the COURSES table. If the @Column annotation is not specified automatically, the layout name will be used as the column name.