SecondaryTable « Map « JPA Q&A

1. Problem using @SecondaryTable in Hibernate

Abridged version of my schema:

id int not null -- PK
name varchar(255) not null

utility_id -- FK to utility
use_magic tinyint(1) not null default 0
There is a one-to-one mapping between these two tables. ...

2. Hibernate mapping and inheritance issues with @SecondaryTable

I have a pretty simple class hierarchy structure that is listed below, each sub class having a @DiscriminatorValue enumeration type, which works very well. Abstract class: AbstractNode (abstract class mapped to the Node ...

3. @SecondaryTable annotation problem

I have following model,

@Table(name = "user")
@SecondaryTable(name = "user_personal_details", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "user_id", referencedColumnName = "user_id")}),
@SecondaryTable(name = "user_address", pkJoinColumns = {@PrimaryKeyJoinColumn(name = "user_id", referencedColumnName = "user_id")}),
@SecondaryTable(name = "user_contact_info", pkJoinColumns = {@PrimaryKeyJoinColumn(name ...

5. Problem using @SecondaryTable annotation

6. JPA @SecondaryTable used only for reads

7. @SecondaryTable xml equivalent

Hi Due to some business reasons, we are pushed to use hbm(xml) in place of annotations. I am looking how to implement @SecondaryTable in xml. The join-table seems to be a good alternative. But, with join-table, I will have to have a different object mapping for the joined table. Could someone please point me how I could acheive the @SecondaryTable equivalent?? ...

8. Problem with @SecondaryTable

@Entity @Table(name = "forum_topics") @SecondaryTables ( { @SecondaryTable(name="forum_messages", pkJoinColumns={@PrimaryKeyJoinColumn(name="id", referencedColumnName="firstMessage_id")}) } ) public class Topic extends Domain { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false) Integer id; @Column(name ...

10. @SecondaryTable and Inheritance

@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn public class User { @Id private Long id; ...... } @Entity @SecondaryTable(name="external_user") @Table(appliesTo="external_user",optional=false) public class ExternalUser extends User { @Column(table="external_user") private String name; ...... } @Entity @SecondaryTable(name="external_user") public class Guest extends ExternalUser { ...

11. @Column with table reference for @SecondaryTable in parent

I have a deep Class Hierarchy with a shallow Table hierarchy. The class hierarchy is (more or less): Code: @Entity @Table(name = "ANCESTOR_TABLE") @Inheritance(strategy = SINGLE_TABLE) @DiscriminatorColumn(name = "TYPE", discriminatorType = STRING, length = 3) public abstract class Ancestor { @Id @Column(name = "ID") private Long id; } @Entity @DiscriminatorValue("AAA") @SecondaryTable(name = "PARENT_TABLE") public class Parent ...

12. Can force @SecondaryTable to use inner joins?

13. @SecondaryTable questions

14. @SecondaryTable: primary record already exists?

I have an entity that spans two tables, primary_table and secondary_table. I've annotated it properly with the @SecondaryTable annotation. It just so happens that in my database, primary_table has more records in it than secondary_table. Another way to think of this is that the primary_table does not just store instances of my entity, but instances of other objects as well. At ...