@Table
From CauchoWiki
The @Table annotation specifies the name of the database table for an entity. If the @Table is not specified the @Entity name is used instead.
@Entity
@Table(name="test")
public class TestBean {
...
}
[edit] Annotation Definition
public @interface Table {
String name() default "";
String catalog() default "";
String schema() default "";
UniqueConstraint[] uniqueConstraints() default {};
}
| attribute | description | default |
|---|---|---|
| name | the database table name | the @Entity name |
| catalog | the database catalog | |
| schema | the database schema | |
| uniqueConstraints | constraint directives when creating the database |
Many applications will only use the name attribute. The uniqueConstraints are used if create-database-schema is true and the table does not exist in the database.
[edit] Related annotations
- @Entity the owning entity
- @SecondaryTable specifies a table where extra columns are stored.
- @Column specifies database column name and types
- @JoinColumn specifies column names for foreign keys
[edit] Example
@Entity
@Table(name="test")
public class TestBean {
@Id
private int id;
@Basic
private String data;
}
create table test (
ID integer primary key,
DATA varchar(255)
)
