jpa 总结

@Entity
Specifies that the class is an entity. This annotation is applied to the entity class.
----------------------------------------------------------------------
@Table
This annotation specifies the primary table for the annotated entity. Additional tables may be specified using SecondaryTable  or SecondaryTables annotation.
If no Table annotation is specified for an entity class, the default values apply.

java.lang.String catalog
          (Optional) The catalog of the table.
java.lang.String name
          (Optional) The name of the table.
java.lang.String schema
          (Optional) The schema of the table.
UniqueConstraint[] uniqueConstraints
          (Optional) Unique constraints that are to be placed on the table

----------------------------------------------------------------------
@ManyToOne
This annotation defines a single-valued association to another entity class that has many-to-one multiplicity. It is not normally necessary to specify the target entity explicitly since it can usually be inferred from the type of the object being referenced.

targetEntity
public abstract java.lang.Class targetEntity
    (Optional) The entity class that is the target of the association.
    Defaults to the type of the field or property that stores the association.
    Default:
        void.class

cascade
public abstract CascadeType[] cascade
    (Optional) The operations that must be cascaded to the target of the association.
    By default no operations are cascaded.
    Default:
        {}

fetch
public abstract FetchType fetch
    (Optional) Whether the association should be lazily loaded or must be eagerly fetched. The EAGER strategy is a requirement on the persistence provider runtime that the associated entity must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime.
    Default:
        javax.persistence.FetchType.EAGER

optional
public abstract boolean optional
    (Optional) Whether the association is optional. If set to false then a non-null relationship must always exist.
    Default:
        true

----------------------------------------------------------------------

@OneToMany
Defines a many-valued association with one-to-many multiplicity.

If the collection is defined using generics to specify the element type, the associated target entity type need not be specified; otherwise the target entity class must be specified.

    Example 1: One-to-Many association using generics

    In Customer class:
    @OneToMany(cascade=ALL, mappedBy="customer")
    public Set getOrders() { return orders; }

    In Order class:
    @ManyToOne
    @JoinColumn(name="CUST_ID", nullable=false)
    public Customer getCustomer() { return customer; }

    Example 2: One-to-Many association without using generics

    In Customer class:
    @OneToMany(targetEntity=com.acme.Order.class, cascade=ALL,
            mappedBy="customer")
    public Set getOrders() { return orders; }

    In Order class:
    @ManyToOne
    @JoinColumn(name="CUST_ID", nullable=false)
    public Customer getCustomer() { return customer; }


targetEntity
public abstract java.lang.Class targetEntity
    (Optional) The entity class that is the target of the association. Optional only if the collection property is defined using Java generics. Must be specified otherwise.
    Defaults to the parameterized type of the collection when defined using generics.
    Default:
        void.class

cascade
public abstract CascadeType[] cascade
    (Optional) The operations that must be cascaded to the target of the association.
    Defaults to no operations being cascaded.
    Default:
        {}

fetch
public abstract FetchType fetch
    (Optional) Whether the association should be lazily loaded or must be eagerly fetched. The EAGER strategy is a requirement on the persistenceprovider runtime that the associatedentities must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime.
    Default:
        javax.persistence.FetchType.LAZY

mappedBy
public abstract java.lang.String mappedBy
    The field that owns the relationship. Required unless the relationship is unidirectional.
    Default:
        ""
----------------------------------------------------------------------


@ManyToMany
Defines a many-valued association with many-to-many multiplicity. If the Collection is defined using generics to specify the element type, the associated target entity class does not need to be specified; otherwise it must be specified.

Every many-to-many association has two sides, the owning side and the non-owning, or inverse, side. The join table is specified on the owning side. If the association is bidirectional, either side may be designated as the owning side.

The same annotation elements for the OneToMany annotation apply to the ManyToMany annotation.

    Example 1:
    In Customer class:
    @ManyToMany
    @JoinTable(name="CUST_PHONES")
    public Set getPhones() { return phones; }
    In PhoneNumber class:
    @ManyToMany(mappedBy="phones")
    public Set getCustomers() { return customers; }

    Example 2:
    In Customer class:
    @ManyToMany(targetEntity=com.acme.PhoneNumber.class)
    public Set getPhones() { return phones; }
    In PhoneNumber class:
    @ManyToMany(targetEntity=com.acme.Customer.class, mappedBy="phones")
    public Set getCustomers() { return customers; }
  
    Example 3:
    In Customer class:
    @ManyToMany
    @JoinTable(name="CUST_PHONE",
        joinColumns=
            @JoinColumn(name="CUST_ID", referencedColumnName="ID"),
        inverseJoinColumns=
            @JoinColumn(name="PHONE_ID", referencedColumnName="ID")
        )
    public Set getPhones() { return phones; }
    In PhoneNumberClass:
    @ManyToMany(mappedBy="phones")
    public Set getCustomers() { return customers; }



targetEntity
public abstract java.lang.Class targetEntity
    (Optional) The entity class that is the target of the association. Optional only if the collection property is defined using Java generics. Must be specified otherwise.
    Defaults to the parameterized type of the collection when defined using generics.
    Default:
        void.class

cascade
public abstract CascadeType[] cascade
    (Optional) The operations that must be cascaded to the target of the association.
    Defaults to no operations being cascaded.
    Default:
        {}

fetch
public abstract FetchType fetch
    (Optional) Whether the association should be lazily loaded or must be eagerly fetched. The EAGER strategy is a requirement on the persistenceprovider runtime that the associatedentities must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime.
    Default:
        javax.persistence.FetchType.LAZY

mappedBy
public abstract java.lang.String mappedBy
    The field that owns the relationship. Required unless the relationship is unidirectional.
    Default:

----------------------------------------------------------------------
@JoinTable
This annotation is used in the mapping of associations. It is specified on the owning side of a many-to-many association, or in a unidirectional one-to-many association.

If the JoinTable annotation is missing, the default values of the annotation elements apply. The name of the join table is assumed to be the table names of the associated primary tables concatenated together (owning side first) using an underscore.

    Example:
    @JoinTable(
    name="CUST_PHONE",
    joinColumns=
        @JoinColumn(name="CUST_ID", referencedColumnName="ID"),
    inverseJoinColumns=
        @JoinColumn(name="PHONE_ID", referencedColumnName="ID")
    )

name
public abstract java.lang.String name
    (Optional) The name of the join table.
    Defaults to the concatenated names of the two associated primary entity tables, separated by an underscore.
    Default:
        ""

catalog
public abstract java.lang.String catalog
    (Optional) The catalog of the table.
    Defaults to the default catalog.
    Default:
        ""

schema
public abstract java.lang.String schema
    (Optional) The schema of the table.
    Defaults to the default schema for user.
    Default:
        ""

joinColumns
public abstract JoinColumn[] joinColumns
    (Optional) The foreign key columns of the join table which reference the primary table of the entity owning the association (i.e. the owning side of the association).
    Uses the same defaults as for JoinColumn.
    Default:
        {}

inverseJoinColumns
public abstract JoinColumn[] inverseJoinColumns
    (Optional) The foreign key columns of the join table which reference the primary table of the entity that does not own the association (i.e. the inverse side of the association).
    Uses the same defaults as for JoinColumn.
    Default:
        {}

uniqueConstraints
public abstract UniqueConstraint[] uniqueConstraints
    (Optional) Unique constraints that are to be placed on the table. These are only used if table generation is in effect.
    Defaults to no additional constraints.
    Default:
        {}

----------------------------------------------------------------------

@JoinColumn
Is used to specify a mapped column for joining an entity association.

   Example:

   @ManyToOne
   @JoinColumn(name="ADDR_ID")
   public Address getAddress() { return address; }


name
public abstract java.lang.String name
    (Optional) The name of the foreign key column. The table in which it is found depends upon the context. If the join is for a OneToOne or Many- ToOne mapping, the foreign key column is in the table of the source entity. If the join is for a ManyToMany, the foreign key is in a join table. Default (only applies if a single join column is used): The concatenation of the following: the name of the referencing relationship property or field of the referencing entity; "_"; the name of the referenced primary key column. If there is no such referencing relationship property or field in the entity, the join column name is formed as the concatenation of the following: the name of the entity; "_"; the name of the referenced primary key column.
    Default:
        ""

referencedColumnName
public abstract java.lang.String referencedColumnName
    (Optional) The name of the column referenced by this foreign key column. When used with relationship mappings, the referenced column is in the table of the target entity. When used inside a JoinTable annotation, the referenced key column is in the entity table of the owning entity, or inverse entity if the join is part of the inverse join definition. Default (only applies if single join column is being used): The same name as the primary key column of the referenced table.
    Default:
        ""

unique
public abstract boolean unique
    (Optional) Whether the property is a unique key. This is a shortcut for the UniqueConstraint annotation at the table level and is useful for when the unique key constraint is only a single field. It is not necessary to explicitly specify this for a join column that corresponds to a primary key that is part of a foreign key.
    Default:
        false

nullable
public abstract boolean nullable
    (Optional) Whether the foreign key column is nullable.
    Default:
        true

insertable
public abstract boolean insertable
    (Optional) Whether the column is included in SQL INSERT statements generated by the persistence provider.
    Default:
        true

updatable
public abstract boolean updatable
    (Optional) Whether the column is included in SQL UPDATE statements generated by the persistence provider.
    Default:
        true

columnDefinition
public abstract java.lang.String columnDefinition
    (Optional) The SQL fragment that is used when generating the DDL for the column.
    Defaults to the generated SQL for the column.
    Default:
        ""

table
public abstract java.lang.String table
    (Optional) The name of the table that contains the column. If a table is not specified, the column is assumed to be in the primary table of the applicable entity.
    Default:
        ""

你可能感兴趣的:(sql,jpa)