@Table

From CauchoWiki

Jump to: navigation, search


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

[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)
 )
Personal tools