the problem is the "fetchType" attribute on your relationship. It defaults to "FetchType.LAZY", which means that the other side of the relation is not loaded until required. If the entity gets detached and the relationship field is not loaded, you will get this exception on client side.
To work around you could
a) set the fetchType to "FetchType.EAGER" (not recommended for ManyToMany)
b) explicitely force loading the relationship field BEFORE the entity gets detached (before the session bean method is left).
To do so: call e.g. "student.getCourses().size();" after loading a student.
Calling only "student.getCourses();" does not help, you have to access the collection content to make it load.
Hope this helps
Thanks wolfgang it worked