@SecondaryTable

From CauchoWiki

Jump to: navigation, search


The @SecondaryTable annotation specifies the name of a secondary database table for an entity, when the entity is split across multiple tables.

 @Entity
 @Table(name="test")
 @SecondaryTable(name="ext")
 public class TestBean {
     ...
 }

[edit] Annotation Definition

 public @interface SecondaryTable {
     String name() default "";
     String catalog() default "";
     String schema() default "";
     PrimaryKeyJoinColumn []pkJoinColumns() default{};
     UniqueConstraint[] uniqueConstraints() default {};
 }
attribute description default
name the database table name the @Entity name
catalog the database catalog
schema the database schema
pkJoinColumns the key columns used to join with the primary @Table
uniqueConstraints constraint directives when creating the database


[edit] Related annotations

[edit] Example

 @Entity
 @Table(name="test")
 @SecondaryTable(name="ext")
 public class TestBean {
 @Id
 private int id;

 @Basic
 @Column(table="ext")
 private String data;
 }
 create table test (
     ID integer primary key
 )

 create table ext (
     ID integer primary key,

     DATA varchar(255)
 )
Personal tools