Possible to perform conversion between "null" and "-1" on foreign key column?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Possible to perform conversion between "null" and "-1" on foreign key column?

Joachim Kanbach
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
_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Loading...