Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Generic Relationship

Hello

Thanks for your answer. Yep, you're right it's a bad idea to use a TABLE_PER_CLASS strategy in this cases (I discovered it by crashing myself against a wall :D). It complains about non existing records in the abstract class table representation (of course, the records are in the subclasses tables, ClassA is abstract) so I will start over with a SINGLE_TABLE strategy. One more question,  is there a way to make it work with interfaces too? I mean

public interface InterfaceA{}

@Entity
public class InterfaceAImpl1 implements InterfaceA{}

@Entity
public class InterfaceAImpl2 implements InterfaceA{}

@Entity
public classB{
      @OneToMany 
      protected List<InterfaceA> myInstances; //Sorry, I made a mistake defining the relationship last time as you pointed out
}

I tried, but it says that no fields can reference a non entity class (the InterfaceA). Thanks again!

-------------------------------------
Charles Edward Bedón Cortázar
ITIL Foundation Certified
Open Source Network Inventory for the masses!  http://kuwaiba.sourceforge.net
Linux Registered User #386666


---- Am Tue, 28 Sep 2010 10:22:38 -0500 James Sutherland <jamesssss@xxxxxxxxx> schrieb ----


This should work, as long as you define the OneToMany correctly,
i.e.
@OneToMany
protected List<ClassA> myInstances;

or if you want a OneToOne
@OneToOne
protected ClassA myInstance;

What error are you getting?

In general using TABLE_PER_CLASS with relationships is not a good idea.
Normally using SINGLE_TABLE or JOINED is better.


Charles Bedon wrote:
>
> Hello
>
> I'm really new to JPA, and I'm using EclipselLink as PP, but as I'm a bit
> short of time I haven't been able to dig into the documentation deep
> enough. I have these entity classes:
>
> public abstract class ClassA{...}
>
>
> public class ClassA_1 extends ClassA{...}
>
>
> public class ClassA_2 extends ClassA{...}
>
>
> And I'd like another entity class something doing this, in order to be
> able to reference an instance of ClassA_1 or ClassA_2:
>
>
> public class ClassB{
> ....
>
>
> @OneToMany
> protected ClassA myInstance;
>
>
> ...
> }
>
>
> Is this possible? I'm currently using an awful workaround involving an
> "adapter" as a wildcard for this relationship. I'm using a table per class
> strategy. Thanks for your input!
>
>
>


-----
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
--
View this message in context: http://old.nabble.com/Generic-Relationship-tp29776432p29826100.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