Skip to main content

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

Thanks James for replying,

I didn't debug at first any further once I saw that isOneToOneMapping
call. Now that you mentioned ManyToOne will return true for that as
well, I've debugged again, and found that owning mapping is
DirectToFieldMapping and that instead of ManyToOneAccessor owning side
attribute has BasicAccessor.

Further debugging showed that processing annotations determines that
there are NO annotations on getter for the owning entity attribute
(isManyToOne returns false so buildAccessor in ClassAccessor falls
back to BasicAccessor). Entity implements an interface, and part of
the interface is that attribute getter. In interface getter has no JPA
annotations, but in entity implementation it does, @ManyToOne and
@JoinColumn. Type hierarchy is as follows:


interface A<T extends B> {
public T getB();
}

interface B<T extends A> {
public List<T> getAs();
}

@Entity
class EA implements A<EB> {
  @Override
    @ManyToOne(cascade = CascadeType.ALL, targetEntity = EB.class)
    @JoinColumn(name = "EB_ID", nullable = false)
  public EB getB() {
}
}

@Entity
class EB implements B<EA> {
@OneToMany(mappedBy = "b", cascade = CascadeType.ALL,
    targetEntity = EA.class)
  public List<EA> getAs() {
}
}

This mapping works well on Java SE 5 environment, but it doesn't work
on Java SE 6. In both cases Java EE 5 and Glassfish 2.1.1 are used,
TopLink essentials 2.1-31 provided by Glassfish.

It's still not clear to me why this mapping doesn't work on Java SE 6,
but moving JPA annotations from methods to fields solved it for now.

Regards,
Stevo.

On Thu, Sep 1, 2011 at 5:35 PM, James Sutherland <jamesssss@xxxxxxxxx> wrote:
>
> What is your code for the two classes in error?  You most like have a
> OneToMany back instead of ManyToOne.  Check that your code is correct and
> compiled/deployed correctly.
>
> The code in TopLink Essentials is fine, isOneToOneMapping() in the model is
> true for ManyToOne as well as OneToOne.
>
>
>
> Stevo Slavic wrote:
>>
>> 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.
>>
>>
>
>
> -----
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
> Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
> Performance
> --
> View this message in context: http://old.nabble.com/Toplink-bidirectional-OneToMany-tp32364754p32380430.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top