Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Toplink bidirectional OneToMany

Hello eclipselink users,

First of all, is it ok to ask toplink questions on this mailing list?

Assuming it is, here is my case.
In a project using (legacy) technologies like jpa 1.0, glassfish 2.1.1
(with provided toplink 2.1-b31g-fcs) I'm getting infamous
TOPLINK-7244,

"An incompatible mapping has been encountered between [class X] and
[class Y]. This usually occurs when the cardinality of a mapping does
not correspond with the cardinality of its backpointer."

In this (see http://download.oracle.com/docs/cd/B10464_05/web.904/b10313/mapping.htm#1108697
) toplink guide paragraph there is following statement:

"Use one-to-many mappings for relationships between entity beans or
between an entity bean and a collection of privately owned regular
Java objects. When you create one-to-many mappings, also create a
one-to-one mapping from the target objects back to the source."

In oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.OneToManyAccessor.process()
method when mappedBy is specified so that many part is owner of the
relationship, toplink enforces that owning many side instead of having
@ManyToOne has @OneToOne annotation

{code}
            // Create a 1-M mapping and process common collection mapping
            // metadata.
            OneToManyMapping mapping = new OneToManyMapping();
            process(mapping);

            // Non-owning side, process the foreign keys from the owner.
			OneToOneMapping ownerMapping = null;
            if (getOwningMapping().isOneToOneMapping()){
            	ownerMapping = (OneToOneMapping) getOwningMapping();
            } else {
				// If improper mapping encountered, throw an exception.
            	getValidator().throwInvalidMappingEncountered(getJavaClass(),
getReferenceClass());
            }
{code}

What's wrong with toplink, even @OneToMany jpa 1.0 javadoc lists
following as first example:


    Example 1: One-to-Many association using generics

    In Customer class:

    @OneToMany(cascade=ALL, mappedBy="customer")
    public Set getOrders() { return orders; }

    In Order class:

    @ManyToOne
    @JoinColumn(name="CUST_ID", nullable=false)
    public Customer getCustomer() { return customer; }



What am I missing here?

Regards,
Stevo.


Back to the top