Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » interfaces
interfaces [message #390038] Thu, 09 July 2009 16:47 Go to next message
Andreas Leue is currently offline Andreas Leue
Messages: 6
Registered: July 2009
Junior Member
Hi,

JPA standard says

"An enum or interface should not be designated as an entity"

I googled a bit around and it seems
http://stackoverflow.com/questions/281503/jpa-mapping-interf aces
it might work somewhere else.

Anyway - how do you do it?

Assuming I have interface Person and implementing classes
Programmer and Manager. Somewhere else, I have an attribute
List<Person>, or a plain attribute Person.

I've read the suggestion to make the interface an abstract class.
Is that the only workaround?

What do you do in case of multiple interfaces? Are you lost then?

Thanks for help,
Andreas
Re: interfaces [message #390050 is a reply to message #390038] Mon, 13 July 2009 10:16 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

JPA does not have support for mapping interfaces, but EclipseLink does
have support for interface descriptor and variable 1-1 mappings.

You can define a OneToOne relationship to an interface using the
@VariableOneToOne EclipseLink annotation.

There is currently no annotation for interface descriptors, but you can
define them using a SessionCustomizer and create a RelationalDescriptor of
interface type (setJavaInterface()).

You could also make it an abstract class, or define an abstract class in
addition to the interface.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: interfaces [message #390289 is a reply to message #390050] Tue, 14 July 2009 16:34 Go to previous messageGo to next message
Andreas Leue is currently offline Andreas Leue
Messages: 6
Registered: July 2009
Junior Member
Dear James,

thank you for the clarification.

> You can define a OneToOne relationship to an interface using the
> @VariableOneToOne EclipseLink annotation.

Is there a notation to do this inside xml mappings?

> There is currently no annotation for interface descriptors, but you
> can define them using a SessionCustomizer and create a
> RelationalDescriptor of interface type (setJavaInterface()).

I tried defining a mapping for an interface in xml, but get a null pointer
exception at
org.eclipse.persistence.internal.jpa.metadata.accessors.clas ses.EntityAccessor
line 190:

EntityAccessor parentAccessor =
getProject().getEntityAccessor(parent.getName());

I guess that "parent" is null, since interfaces do not habe a superclass.
Is this supposed to work, or am I on the wrong track by trying this?

Besides - I'm just curious: am I the only one missing this feature in JPA?
To me it seems rather natural to map interfaces.

Andreas
Re: interfaces [message #390297 is a reply to message #390289] Thu, 16 July 2009 10:15 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The EclipseLink orm.xml support mirrors the EclipseLink annotations, its
schema is in the eclipselink.jar and on the wiki.

Please include your mappings and the full exception stack trace.


James : Wiki : Book : Blog : Twitter
Re: interfaces [message #390512 is a reply to message #390289] Tue, 21 July 2009 05:48 Go to previous messageGo to next message
Ana Oleski is currently offline Ana Oleski
Messages: 22
Registered: July 2009
Junior Member
Hi Andreas,

I miss it too, I logged an enhancement request

http://bugs.eclipse.org/275836

You can vote for it :-)

Ana

Andreas Leue wrote:


> Besides - I'm just curious: am I the only one missing this feature in JPA?
> To me it seems rather natural to map interfaces.

> Andreas
Re: interfaces [message #390590 is a reply to message #390289] Fri, 24 July 2009 10:57 Go to previous messageGo to next message
Michael OBrien is currently offline Michael OBrien
Messages: 34
Registered: July 2009
Member
Andreas,
Hi, the NPE you are experiencing should be fixed after the rev 4170
transaction of 13 May 2009.
You may pick up any trunk or 2.0 label after this rev/date and retest
your investigations.

http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/o rg.eclipse.persistence.jpa/src/org/eclipse/persistence/inter nal/jpa/metadata/accessors/classes/EntityAccessor.java?r=417 0
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/o rg.eclipse.persistence.jpa/src/org/eclipse/persistence/inter nal/jpa/metadata/accessors/classes/EntityAccessor.java?r1=40 58&r2=4170
http://fisheye2.atlassian.com/changelog/~author=jsutherla/ec lipselink/?cs=4170


From your post it looks like you are running code 1.1 or 2.0 code
somewhere between rev 2968 (16 Dec 2008) and rev 3376 (28 Jan 2009)
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/o rg.eclipse.persistence.jpa/src/org/eclipse/persistence/inter nal/jpa/metadata/accessors/classes/EntityAccessor.java?r=337 6

thank you for using EclipseLink
/michael
Re: interfaces [message #480195 is a reply to message #390512] Fri, 14 August 2009 06:44 Go to previous messageGo to next message
Andreas Leue is currently offline Andreas Leue
Messages: 6
Registered: July 2009
Junior Member
I did!
Re: interfaces [message #480196 is a reply to message #390590] Fri, 14 August 2009 06:48 Go to previous message
Andreas Leue is currently offline Andreas Leue
Messages: 6
Registered: July 2009
Junior Member
Cool! I'll try immediately... (wasn't monitoring the thread anymore)

Thanks 2 all of you!
Previous Topic:jpa2.0 - TypesafeMetamodel, Criteria API
Next Topic:OneToMany two times
Goto Forum:
  


Current Time: Wed Jul 30 11:11:43 EDT 2014

Powered by FUDForum. Page generated in 0.05697 seconds