Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Possible to perform conversion between "null" and "-1" on foreign key column?

Hi all,

I have to work with a legacy database that has the convention to have a "NOT NULL" constraint on *every* column. If a foreign key is empty, the convention is to use the value -1 instead of null. This works because those (integer) foreign key columns don't actually use foreign key constraints - they are identified as such merely by a naming convention like adding "_dbid" to the name of the referenced table.

I was hoping to use a @Converter on my JPA entity fields to handle this, like the user at https://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg06571.html did. But then I saw that @Converter can only be applied to @Basic mappings.

So my question is if there is a way to fulfill this convention with a relationship mapping like a @ManyToOne? Or is the only way out to map the integer value and handle all joins explicitly?


Best regards,
Joachim Kanbach


Back to the top