You can create a uni-directional OneToMany in TopLink Essentials, just not
through annotations a JPA does not allow this. You could use a TopLink
DescriptorCustomizer to add a TopLink OneToManyMapping to your descriptor
for One. The main issue is that you are responsible for mapping and writing
the foreign key value, if you do not wish to define a ManyToOne (which I
would strongly recommend) then you must define a Basic mapping for the
foreign key and ensure it is updated in your object model. In general if
you do not wish to have a ManyToOne back from a OneToMany using a join table
as JPA does is the best and the strongly recommended solution.
If you do not wish to have the join table, and do not want to map the
foreign key, then you could use an AggregateCollectionMapping in TopLink.
You will also need to customize the target Two descriptor and set it to be
an aggregateCollectionDescriptor(). You target Two class will then be
treated as an Embeddable.
Aleksei Valikov-3 wrote:
>
> 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
>
>
-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.oracle.com/technology/products/ias/toplink/ Oracle TopLink ,
http://www.eclipse.org/eclipselink/
EclipseLink , https://glassfish.dev.java.net/javaee5/persistence/ TopLink
Essentials
Wiki: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence ,
http://wiki.eclipse.org/EclipseLink EclipseLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink ,
http://www.nabble.com/java.net---glassfish-persistence-f13455.html Glassfish
Persistence
--
View this message in context: http://www.nabble.com/%40OneToMany-without-join-table-with-TopLink-tp14395525p14398301.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.