users@glassfish.java.net

Re: Foreign key question

From: <glassfish_at_javadesktop.org>
Date: Mon, 07 May 2007 14:11:41 PDT

> How do you specify the relationship type? Do you use
> the Base type or the Subclass type?

The Subclass type. So my actual example is like this:

BaseObject <--extends-- PartyEntity <--ties-- PartyPostalAddressBinding --ties--> PostalAddressEntity

So a PartyPostalAddressBinding is an @Entity that ties a PartyEntity to a PostalAddressEntity (and also stores its type, but that's irrelevant here).

The binding class says, in part, this:

[code]@ManyToOne(optional=false, fetch=FetchType.EAGER)
  @JoinColumn(name="PartyID", nullable=false)
  public PartyEntity getPartyEntity() {
    return this.partyEntity;
  }[/code]

But the foreign key generated says this:

[code]CONSTRAINT [PrtyPstlddrssBndnPrtyD] FOREIGN KEY ([PartyID])
  REFERENCES [dbo].[BaseObject] ([PK])[/code]

Note that it points to BaseObject, not PartyEntity.

> Which persistence provider do
> you use?

I use the Toplink provider that's bundled with Glassfish.

I'm using Java 6.0 update 1, Glassfish v2b45 and MS SQL Server 2005 Express Edition.

Laird
[Message sent by forum member 'ljnelson' (ljnelson)]

http://forums.java.net/jive/thread.jspa?messageID=215892