☰ See All Chapters |
@ Table Annotation in JPA
Table annotation is used to map the entity class to the database table. If you omit the Table annotation, base entity classes (Super class of entity class if entity class extends any other class) default to a table with their unqualified class name.
Tables have the following properties:
String name: The name of the table. Defaults to the unqualified entity class name.
String schema: The table's schema. If you do not name a schema, JPA uses the default schema for the database connection.
String catalog: The table's catalog. If you do not name a catalog, JPA uses the default catalog for the database connection.
UniqueConstraint[] uniqueConstraints: An array of unique constraints to place on the table.
package com.java4coding;
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;
@Entity @Table(name = "STUDENT") public class Student { @Id @Column(name = "id") private int id;
@Column(name = "fistName") private String firstName;
@Column(name = "lastName") private String lastName;
@Column(name = "marks") private int marks;
public Student() {
}
public Student(int id, String firstName, String lastName, int marks) { super(); this.id = id; this.firstName = firstName; this.lastName = lastName; this.marks = marks; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public int getMarks() { return marks; }
public void setMarks(int marks) { this.marks = marks; } } |
All Chapters