[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] @JoinColumn: Using a function in "name" or "referencedColumnName"
|
JPA only allows basic fields/foreign keys in JoinColumns. You can do this in
EclipseLink using a DescriptorCustomizer. Get the mapping from the
descriptor and set its selectionCriteria using an EclipseLink Expression.
The Expression can use the function or any other complex criteria.
Zarar Siddiqi wrote:
>
> Hello,
>
> I've come across a situation where I need to use a DB2 function inside
> @JoinColumn attributes. I want to have something like this:
>
> @OneToMany @JoinColumns({
> @JoinColumn(name="PERSON_ID", referencedColumnName =
> "PERSON_ID"),
> @JoinColumn(name="PERSON_TYPE", referencedColumnName = "*
> SUBSTR(PERSON_TYPE,1,5)*")
> })
>
> However, I get the following exception message when I do this since
> SUBSTR(PERSON_TYPE,1,5) isn't really a column. If I put PERSON_TYPE,
> everything works fine but it's incorrect business logic.
>
> *When the source entity class uses a composite primary key, a @JoinColumn
> must be specified for each join column using the @JoinColumns. Both the
> name
> and the referenceColumnName elements must be specified in each such
> @JoinColumn.*
>
> I understand that this isn't exactly how most composite key relationship
> are
> modeled but I'm working with a legacy system. Any ideas for a workaround?
> I really don't want to use a native query.
>
> Thanks
>
>
-----
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://www.nabble.com/%40JoinColumn%3A-Using-a-function-in-%22name%22-or-%22referencedColumnName%22-tp25981651p26010279.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.