The fields or properties will be annotated by @Id, @Basic, etc. Amber will detect either field or property annotation by the type for the @Id. In other words, if Amber sees an @Id on a field, it will use field access. If Amber sees @Id on a method, it will use property access.

package javax.persistence; @Target(TYPE) @Retention(RUNTIME) public @interface Entity { String name() default ""; }

Specifies a secondary database table for an entity bean. The secondary table will contain the fields with a secondaryTable in the @Column.

package javax.persistence; @Target(TYPE) @Retention(RUNTIME) public @interface SecondaryTable { String name() default ""; String catalog() default ""; String schema() default ""; PrimaryKeyJoinColumn []pkJoinColumns() default {}; UniqueConstraint []uniqueConstraints() default {}; }

Specifies the database table for an entity bean. The default table name is the class name.

package javax.persistence; @Target(TYPE) @Retention(RUNTIME) public @interface Table { String name() default ""; String catalog() default ""; String schema() default ""; UniqueConstraint []uniqueConstraints() default {}; }

Marks a field as a persistent field.

The fetch types are:

@Entity public class Course { @Basic public String getName() ... } @Entity public class Course { @Basic(fetch=FetchType.LAZY) public String getMassiveText() ... } package javax.persistence; @Target({Method, FIELD}) @Retention(RUNTIME) public @interface Basic { FetchType fetch() default EAGER; boolean optional() default true; }

Specifies the field's SQL column name as well as any CREATE TABLE properties for auto generation.

@Entity public class Course { @Basic @Column(unique=true, nullable=false, length=32) public String getName() ... } @Target({Method, FIELD}) @Retention(RUNTIME) public @interface Column { String name() default ""; boolean unique() default false; boolean nullable() default true; boolean insertable() default true; boolean updateable() default true; String columnDefinition() default ""; String table() default ""; int length() default 255; int precision() default 0; int scale() default 0; boolean specified() default true; }

Marks a field as a primary key. The @Id may be used in combination with @GeneratedValue to specify a generator for automatic key generation when new objects are created.

The default column name is "ID".

import javax.persistence.*; @Entity public class Course { @Id @Column(name="t_id") @GeneratedValue public long getId() ... } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface Id { }

Used with @Id to specify a generator for automatic key generation when new objects are created.

The generator types are:

For SEQUENCE and TABLE, Resin will create the sequence name as "${table}_cseq".

import javax.persistence.*; @Entity public class Course { @Id @GeneratedValue public long getId() ... } import javax.persistence.*; @Entity public class Course { @Id @GeneratedValue(strategy=GeneratorType.AUTO generator="COURSE_SEQ") public long getId() ... } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface GeneratedValue { GenerationType strategy() default AUTO; String generator() default ""; }

Defines an association table for a many-to-many relation.

@Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinTable { String table() default ""; String catalog() default ""; String schema() default ""; JoinColumn []joinColumns() default {}; JoinColumn []inverseJoinColumns() default {}; UniqueContraint []uniqueConstraint() default {}; }

Defines a join (foreign) columns. Used for @ManyToOne.

See also @Column for corresponding definition for @Basic columns.

See the Many-to-One tutorial for a full example.

public class Student { @Id @Column(name="student_id") long getId() @ManyToOne @JoinColumn(name="house_id") public House getHouse() } CREATE TABLE Student { student_id BIGINT PRIMARY KEY auto_increment house_id BIGINT REFERENCES House(id) ) @Target({TYPE, METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinColumn { String name() default ""; String referencedColumnName() default ""; boolean unique() default false; boolean nullable() default false; boolean insertable() default true; boolean updateable() default true; String columnDefinition() default ""; String table() default ""; }

Defines a set of join (foreign) columns for composite keys.

@Target({TYPE,METHOD, FIELD}) @Retention(RUNTIME) public @interface JoinColumns { JoinColumn [] value() default{} }

Marks a field as a many-to-many (association) relation.

The column names are the key columns of the source and target tables.

See the many-to-many tutorial for an example.

@Entity public class Student { @ManyToMany @JoinTable( name="student_course_map", joinColumns={@JoinColumn(name="student_id")}, inverseJoinColumns={@JoinColumn(name="course_id")} ) public Collection getCourses() ... } @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface ManyToMany { String targetEntity default ""; CascadeType []cascade() default {}; FetchType fetch() default LAZY; String mappedBy isInverse() default ""; }

Marks a field as a many-to-one (link) relation.

The default column name is the column name of the target key.

See the many-to-one tutorial for an example.

@Entity public class Student { @ManyToOne @JoinColumn(name="house") public House getHouse() ... } @Target({Method, FIELD}) @Retention(RUNTIME) public @interface ManyToOne { String targetEntity default ""; CascadeType []cascade() default {}; FetchType fetch() default EAGER; boolean optional() default true; }

Marks a field as a one-to-many (collection) relation. Because a one-to-many field is dependent, it needs a @ManyToOne relation on the source table which defines the column.

@Entity public class House { ... @OneToMany(targetEntity=Student.class, mappedBy="house") public Collection getStudents() } @Entity public class Student { ... @ManyToOne @JoinColumn(name="house") public House getHouse() } CREATE TABLE House { id BIGINT PRIMARY KEY ) CREATE TABLE Student { id BIGINT PRIMARY KEY, house BIGINT REFERENCES House(id) ) @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface OneToMany { String targetEntity default ""; CascadeType []cascade() default {}; FetchType fetch() default EAGER; String mappedBy() default ""; }

Marks a field as a one-to-one (dependent link) relation. Because a one-to-one field is dependent, it needs a @ManyToOne relation on the source table which defines the column.

@Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface OneToOne { String targetEntity default ""; CascadeType []cascade() default {}; FetchType fetch() default EAGER; boolean optional() default true; String mappedBy() default ""; }

Configures the discriminator column.

@Target(TYPE) @Retention(RUNTIME) public @interface DiscriminatorColumn { String name() default ""; DiscriminatorType discriminatorType() default STRING; String columnDefinition() default ""; int length() default 31; }

@Inheritance marks the entity bean as supporting inheritance, i.e. the database maps to different Java classes depending on a discriminator value.

@Target(TYPE) @Retention(RUNTIME) public @interface Inheritance { InteritanceType strategy() default SINGLE_TABLE; }
public enum InheritanceType { SINGLE_TABLE, JOINED, TABLE_PER_CLASS }
Copyright (c) 1998-2009 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.