Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] @JoinColumn: Using a function in "name" or "referencedColumnName"

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

Back to the top