Back Home

import javax.persistence.*;

Annotations

  • @NamedNativeQueries
@NamedNativeQueries({
        @NamedNativeQuery(name = "PromotionDBO.getPromotions", query = PromotionDBO.FULL_PROMOTION, resultSetMapping = "promotion-result")}
)
  • @SqlResultSetMapping
@SqlResultSetMapping(name = "promotion-result", classes = { @ConstructorResult(targetClass = PromotionDBO.class, columns = {
        @ColumnResult(name = "XPROMODATA_ID"), @ColumnResult(name = "PROMOTIONID"), @ColumnResult(name = "XBRANCH_ID"),
  • @Entity - PA recognizes two types of persistent classes: @Entity classes and @Embedded classes. Each persistent instance of an entity class - each entity
  • @Table - Specify the database table this Entity maps to using the name attribute of @Table annotation. In the example below, the data will be stored in 'company' table in the database.
  • @Column - Specify the column mapping using @Column annotation.
  • @Id - PrimaryKey: annotate the Id column using @Id
@Entity
@Table(name = "company")
public class Company implements Serializable {
 
  @Id
  @Column(name = "id")
  private int id;
 
...
}
  • @GeneratedValue - Let database generate (auto-increment) the id column.
  • @Version - Control versioning or concurrency using @Version annotation.
  • @OrderBy - Sort your data using @OrderBy annotation. In example below, it will sort all contacts in a company by their firstname in ascending order.
  @OrderBy("firstName asc")
  private Set contacts;

* @Transient

  • @Lob - large objects with @Lob

    == Hibernate Extensions ==

Hibernate Association Mapping Annotations

  • @OneToOne
  • @ManyToOne
  • @OneToMany
  • @ManyToMany
  • @PrimaryKeyJoinColumn
  • @JoinColumn
  • @JoinTable
  • @MapsId

Hibernate Inheritance Mapping Annotations

  • @Inheritance
  • @DiscriminatorColumn
  • @DiscriminatorValue
 
java_persistence.txt · Last modified: 2017/08/15 08:45 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd