On Java Development

All things related to Java development, from the perspective of a caveman.

Java Persistence Annotations

without comments

Introduction

The set of annotations presented in this post are part of the Java Persistence API and originate from the javax.persistence package.

Annotations do not directly affect the logic of the code to which they relate. Annotations provide directives and information to the Java compiler:

  • Compile-time Error Detection: Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compile-time and Deployment-time Processing: Software tools can process annotation information to generate code, XML files, and so forth.
  • Run-time Processing: Some annotations are available to be examined at runtime

 
 

Java Persistence API (JPA)

Java Persistence is the API for the management of persistence and object/relational mapping.

The following lists some of the commonly used annotations available in Java 6.

  • @Entity – Specifies that the class is an entity. This annotation is applied to the entity class.
  • @Table – Specifies the primary table for the annotated entity. Additional tables may be specified using SecondaryTable or SecondaryTables annotation.
  • @EmbeddedId – Applied to a persistent field or property of an entity class or mapped superclass to denote a composite primary key that is an embeddable class.
  • @Embeddable – Defines a class whose instances are stored as an intrinsic part of an owning entity and share the identity of the entity.
  • @Column – Used to specify the mapped column for a persistent property or field
  • @OneToMany – Defines a many-valued association with one-to-many multiplicity
  • @JoinColumns – Defines mapping for composite foreign keys.
  • @JoinColumn – Specifies a column for joining an entity association or element collection
  • @ManyToOne – Defines a single-valued association to another entity class that has many-to-one multiplicity

 
The following classes include the majority of the annotations listed above. Note the annotations are imported come from the javax.persistence package. The class below maps the fields related to a header file and is part of a header-detail relationship. The detail file for the header information defined in this class is presented below it.

 

 
 
The class presented below defines the fields of the detail file that is related to the header file presented above.

Written by admin

July 14th, 2014 at 5:00 am

Posted in JPA annotations

Leave a Reply

You must be logged in to post a comment.