JoinColumn (Java EE 5)

Java EE API


javax.persistence Annotation Type JoinColumn


@Target(value={METHOD,FIELD})
@Retention(value=RUNTIME)
public @interface JoinColumn

Implements: Annotation
@Target(value={METHOD, FIELD})
@Retention(value=RUNTIME)

此类用于指定连接到实体关联的映射列。
示例:

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

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

   Example:

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

Since:
Java Persistence 1.0

Optional Element Summary
 String
 boolean
 String
 boolean
 String
 String
 boolean
 boolean
 

abstract public String name()
(可选)外键列的名称。它所在的表取决于上下文。如果连接针对 OneToOne 或 Many- ToOne 映射,则外键列位于源实体的表格中。如果连接针对 ManyToMany,则外键位于连接表格中。 默认(仅适用于使用单个连接列时):以下内容的串接:引用实体的引用关系属性或字段名称;“_”;引用的主键列的名称。如果实体中没有此类引用关系属性或字段,则连接列名称为以下内容的串接:实体的名称:“_”;引用的主键列的名称。
英文文档:

name

public abstract 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:
""

abstract public String referencedColumnName()
(可选)此外键列引用的列的名称。使用关系映射时,引用的列位于目标实体的表格中。在 JoinTable 注释内部使用时,引用的键列位于所在实体(如果连接是反向连接定义的一部分,则为反向实体)的实体表格中。 默认(仅适用于使用单个连接列时):与引用表格的主键列名称相同。
英文文档:

referencedColumnName

public abstract 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:
""

abstract public boolean unique()
(可选)属性是否为唯一键。这是表格级别的 UniqueConstraint 注释的快捷方式,在唯一的键约束只有一个字段时很有用。主键为外键一部分时,不必为对应于此主键的连接列显式指定此属性。
英文文档:

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

abstract public boolean nullable()
(可选)外键列是否可为 null。
英文文档:

nullable

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

Default:
true

abstract public boolean insertable()
(可选)持久性提供者生成的 SQL INSERT 语句中是否包含该列。
英文文档:

insertable

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

Default:
true

abstract public boolean updatable()
(可选)持久性提供者生成的 SQL UPDATE 语句中是否包含该列。
英文文档:

updatable

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

Default:
true

abstract public String columnDefinition()
(可选)生成该列的 DDL 时使用的 SQL 句段。

默认为为该列生成的 SQL。

英文文档:

columnDefinition

public abstract 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:
""

abstract public String table()
(可选)包含该列的表格的名称。如果没有指定表格,则假设该列位于适用实体的主表格中。
英文文档:

table

public abstract 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:
""


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!