Customizing @ManyToOne?

View: New views
4 Messages — Rating Filter:   Alert me  

Customizing @ManyToOne?

by ljnelson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a VERY complicated join in a legacy database I can't change.  I would like a child object in this context to be able to navigate to his parent via a @ManyToOne operation.  However, there is no direct link from the child to the parent.  In SQL, I need to go through several INNER JOIN clauses to ultimately arrive at the proper destination.

How would I go about customizing this relationship in EclipseLInk?  Is there somewhere I can tell EclipseLink that when someone calls child.getParent() I would like it to run this large query instead?

I had a look at http://wiki.eclipse.org/Customizing_the_EclipseLink_Application_%28ELUG%29 but didn't really know what to look for.

Thanks,
Laird

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Customizing @ManyToOne?

by tch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm pretty sure you can't do this, have you considered using a
database view as a workaround?

./tch



On Fri, Jul 17, 2009 at 4:51 PM, Laird Nelson<ljnelson@...> wrote:

> I have a VERY complicated join in a legacy database I can't change.  I would
> like a child object in this context to be able to navigate to his parent via
> a @ManyToOne operation.  However, there is no direct link from the child to
> the parent.  In SQL, I need to go through several INNER JOIN clauses to
> ultimately arrive at the proper destination.
>
> How would I go about customizing this relationship in EclipseLInk?  Is there
> somewhere I can tell EclipseLink that when someone calls child.getParent() I
> would like it to run this large query instead?
>
> I had a look at
> http://wiki.eclipse.org/Customizing_the_EclipseLink_Application_%28ELUG%29
> but didn't really know what to look for.
>
> Thanks,
> Laird
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Customizing @ManyToOne?

by ljnelson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jul 17, 2009 at 5:42 PM, Tim Hollosy <hollosyt@...> wrote:
I'm pretty sure you can't do this, have you considered using a
database view as a workaround?

Duh; no, that hadn't occurred to me.  Thanks.  Friday brain!

Best,
Laird

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Customizing @ManyToOne?

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can do this using a DescriptorCustomizer and set the selectionSQLString on the OneToOneMapping.

mapping.setSelectionSQLString("Select * from Foo f, Bar, b where ... and f.bar_id = #BAR_ID");

Note "#" is used in custom SQL for parameters.

See,
http://www.eclipse.org/eclipselink/api/1.1.1/org/eclipse/persistence/mappings/ForeignReferenceMapping.html#setSelectionSQLString(java.lang.String)


ljnelson wrote:
I have a VERY complicated join in a legacy database I can't change.  I would
like a child object in this context to be able to navigate to his parent via
a @ManyToOne operation.  However, there is no direct link from the child to
the parent.  In SQL, I need to go through several INNER JOIN clauses to
ultimately arrive at the proper destination.

How would I go about customizing this relationship in EclipseLInk?  Is there
somewhere I can tell EclipseLink that when someone calls child.getParent() I
would like it to run this large query instead?

I had a look at
http://wiki.eclipse.org/Customizing_the_EclipseLink_Application_%28ELUG%29but
didn't really know what to look for.

Thanks,
Laird

_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users