@JoinTable
From CauchoWiki
The @JoinTable annotation specifies an association table used by a @ManyToMany or unidirectional @OneToMany relation.
[edit] Annotation Definition
public @interface JoinTable {
String name() default "";
String catalog() default "";
String schema() default "";
JoinColumn []joinColumns() default{};
JoinColumn []inverseJoinColumns() default {};
UniqueConstraint[] uniqueConstraints() default {};
}
| attribute | description | default |
|---|---|---|
| name | the database table name | the @Entity name |
| catalog | the database catalog | |
| schema | the database schema | |
| joinColumns | the key columns used to join with the source @Table | |
| inverseColumns | the key columns used to join with the target @Table | |
| uniqueConstraints | constraint directives when creating the database |
[edit] See Also
- @Entity the owning entity
- @ManyToMany many-to-many relation
- @OneToMany one-to-many relation
- @JoinColumn join (foreign) column configuration
- Relation catalog
[edit] Example: unidirectional @OneToMany with specified SQL
@Entity @Table(name="s") public class Src { @Id @Column(name="s_id") int getId() { ... } @OneToMany @JoinTable(name="map", joinColumns={@JoinColumn(name="s_key")}, inverseJoinColumns={@JoinColumn(name="d_key")}) Collection<Dst> getChildren() { ... } } @Entity @Table(name="d") public class Dst { @Id @Column(name="d_id") int getId() { ... } }
create table s (
s_id integer primary key
)
create table d (
d_id integer primary key
)
create table map (
s_key integer references(s, s_id),
d_key integer references(d, d_id)
)
