Try one of these 2 suggestions, either one should solve your problem. You shouldn't have to use both of them:
1) Explicitly save the course object before saving the student object.
2) Inverse your inverse relationships, make Student inverse=true and Course inverse=false; In the code you posted, Course is the owner of the relationship so Student would not update Course.