You are currently browsing the daily archive for October 10, 2008.

1. Single table

@Entity

@Table(name=”USERS”)

@Inheritance(strategy=InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(name=”USER_TYPE”,

discriminatorType=DiscriminatorType.STRING, length=1)

public abstract class User implements Serializable { … }

@Entity

@DiscriminatorValue(value=”S”)

public class Seller extends User …

@Entity

@DiscriminatorValue(value=”B”)

public class Bidder extends User

2. Joined tables

@Entity

@Table(name=”USERS”)

@Inheritance(strategy=InheritanceType.JOINED)

@DiscriminatorColumn(name=”USER_TYPE”,

discriminatorType=STRING, length=1)

public abstract class User { … }

@Entity

@Table(name=”SELLERS”)

@DiscriminatorValue(value=”S”)

@PrimaryKeyJoinColumn(name=”USER_ID”)

public class Seller extends User { … }

@Entity

@Table(name=”BIDDERS”)

@DiscriminatorValue(value=”B”)

@PrimaryKeyJoinColumn(name=”USER_ID”)

public class Seller extends User { … }

3. Table per class

@Entity

@Table(name=”USERS”)

@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

public class User {

@Entity

@Table(name=”SELLERS”)

public class Seller extends User {

@Entity

@Table(name=”BIDDERS”)

public class Bidder extends User {

Advertisements