persistence@glassfish.java.net

_at_OneToMany without join table with TopLink

From: Aleksei Valikov <aleksei.valikov_at_gmail.com>
Date: Tue, 18 Dec 2007 12:51:16 +0100

Hi.

I'm trying to implement a @OneToMany association without the join
table under TopLink. Consider two entities One and Two and One has the
following property:

    public List<Two> getOneToManyDefault() {...}

If I just annotate it as follows:

     @OneToMany(cascade = {
        CascadeType.ALL
    })
    public List<Two> getOneToManyDefault() {...}

I get

CREATE TABLE ONE (HJID NUMERIC(19) NOT NULL, DTYPE VARCHAR(31),
PRIMARY KEY (HJID))
CREATE TABLE TWO (HJID NUMERIC(19) NOT NULL, DTYPE VARCHAR(31),
PRIMARY KEY (HJID))

CREATE TABLE ONE_TWO (One_HJID NUMERIC(19) NOT NULL,
oneToManyDefault_HJID NUMERIC(19) NOT NULL, PRIMARY KEY (One_HJID,
oneToManyDefault_HJID))

ALTER TABLE ONE_TWO ADD CONSTRAINT FK_ONE_TWO_oneToManyDefault_HJID
FOREIGN KEY (oneToManyDefault_HJID) REFERENCES TWO (HJID)
ALTER TABLE ONE_TWO ADD CONSTRAINT ... FOREIGN KEY (One_HJID)
REFERENCES ONE (HJID)

So there is an implicit join table generated.
I would like to avoid the join table and have the following:

create table ONE (HJID bigint generated by default as identity (start
with 1), primary key (HJID))
create table TWO (HJID bigint generated by default as identity (start
with 1), ONETOMANYDEFAULT_ONE_ID bigint, primary key (HJID))
alter table TWO add constraint FK1462C312740FD foreign key
(ONETOMANYDEFAULT_ONE_ID) references ONE

This is one table less. Under Hibernate this is produced by the
following annotation:

    @OneToMany(cascade = {
        CascadeType.ALL
    })
    @JoinColumn(name = "ONETOMANYDEFAULT_ONE_ID")

I wonder what the solution for TopLink will be.

Thank you in advance for your time.

Bye.
/lexi