option#1 and option#2 patches are uploaded.
You do not need both patches, either one of them should work.
TestEJBState will work only with patch
OPENJPA-946 and the current patch.
My current patch handles the foreign key problem.
Every time I try to delete a FK, I will check the FKname.
If it does not exist then I go to DB and fetch the FKName.
If option#1 is not preferable for any reason then you can try option2.
Every time I try to add a FK.
I will check in the Mappings if FKName exists.
If it does not exist then a default name will be given.
The default name is local table name + column name of FK.
The only issue with option#2 is that it will work on a new clean database.
So running "mvn clean test -DfailIfNoTests=false" will run fine with out any issues.
If the tables are already created then it will not work because openJPA will think that the default name FK
is new FK and will try to add the existing FK with the new default name.
I think it is an existing issue, same behavior for columns , tables etc...
Please let me know if option#2 is preferable, but my changes are not acceptable because it does not work with existing database. I can add the logic of making it work on existing database also.