Overflying the specific JAA country should be no problem. The only problem I can see that _might_ happen is if you use your future pilot licence on an aircraft registered in the country where you failed your medical _and_ the authority knows that you, who failed their medical, is flying an aircraft on their registry. However, as stated as of above, even if so happens it should pose no problem. In a few years time EASA might have come into effect and all might have changed by then, probably for the better in your case.