Skip to content

Supported JPA annotations

Jeronimo López edited this page Jan 7, 2019 · 2 revisions

By default JFleet reuses existing JPA annotations to map Java object to tables.

JPA allows to define how to map your entities in two ways:

  • entity attributes (instance fields)
  • or the accessors (instance properties)

In JPA by default, the placement of the @Id annotation gives the default access strategy.

JFleet only supports access by entity attributes, and it expects annotations on fields.

The supported annotations are:

  • @Entity: Specifies that the class is an entity.
  • @Table: Specifies the table name. If no value is specified, the class name in lower case is used.
  • @Column: Is used to specify a mapped column for a persistent field. If no value is specified, the field name is used.
  • @Id: Specifies the primary key field of an entity. It is only used to fetch foreign key values in ManyToOne and OneToOne relationships.
  • @MappedSuperclass: Designates a class whose mapping information is applied to the entities that inherit from it. A mapped superclass has no separate table defined for it.
  • @Transient: This annotation specifies that field is not persistent.
  • @Embedded: Defines a persistent field of an entity whose value is an instance of an embeddable class.
  • @EmbeddedId: Is applied to a persistent field of an entity class or mapped superclass to denote a composite primary key that is an embeddable class.
  • @AttributeOverrides: Is used to override mappings of multiple fields.
  • @AttributeOverride: Is used to override the mapping of a basic field or Id field. May be applied to an entity that extends a mapped superclass or to an embedded field to override a basic mapping defined by the mapped superclass or embeddable class.
  • @ManyToOne: Defines a single-valued association to another entity class that has many-to-one multiplicity. The targetEntity value is ignored if provided. Uses the field class annotated.
  • @OneToOne: Defines a single-valued association to another entity that has one-to-one multiplicity. The targetEntity value is ignored if provided. Uses the field class annotated.
  • @JoinColumn: The name of the foreign key column. If no name is provided, the column name is the concatenation of the name of the referencing relationship field of the referencing entity, the char "_", and the name of the referenced primary key column.
  • @Enumerated: Specifies that a persistent field should be persisted as an enumerated type. The used value is specified by the EnumType value. If no annotation is used or no EnumType is used, the default enum type is ORDINAL.
  • @Temporal: This annotation must be specified for persistent fields of type java.util.Date. DATE, TIME and TIMESTAMP values are accepted.

Some common annotations which are not supported are: @GeneratedValue, @OneToMany, @ManyToMany, @JoinColumns and @JoinTable.

These annotations, and many configuration properties in supported annotations, are ignored mainly because has no effect o meaning in the purpose and limitations of JFleet. If you find a relevant annotation or property which could be included create an issue.

JFleet does not manage the Primary Key (@Id) of your entities like other ORMs do and you are responsible of it. You can read more information about the limitations of the @Id annotation in this wiki page.

When JFleet is configured to use JPA annotations you need to add the Javax Persistence API dependency, but it is not necessary to add the dependency to any JPA implementation, just to the API which defines the annotations.

If you don't have any JPA implementation as a dependency in your project, you must add the Javax Persistence API dependency:

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0.2</version>
</dependency>
Clone this wiki locally