Easy learning with example program codes

JPA id annotation

The @Id annotation is used to specify the primary key of an entity. The field or property to which the Id annotation is applied should be one of the following types:
1. Any Java primitive type
2. Any primitive wrapper type.
3. String
4. java.util.Date
5. java.sql.Date
6. java.math.BigDecimal
7. java.math.BigInteger

It is contained in the javax.persistence package. The mapped column for the primary key of the entity is assumed to be the primary key of the primary table. If no Column annotation is specified, the primary key column name is assumed to be the name of the primary key property or field.

JPA field access strategy example:

JPA field access strategy specify that annotation is applied to a field instead of getter method.

private Long studentId;

JPA property access strategy example:

JPA property access strategy specify that annotation is applied to getter method instead of the field.
Note: JPA property access gives the flexibility to modify the value of actual value set in id field if required.

public Long getStudentId()
  return studentId;
Posted in JPA   
Sign Up/ Sign In
Ask a Question

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2018 CodesJava Protection Status SiteMap Reference: Java Wiki