A: 

Try adding @ManyToMany(cascade = CascadeType.ALL) to your Cat object, to cascade your read operations.

With cascading set up properly you can change your saving code to;

Entitymanager em = emf.createEntityManager();

em.getTransaction().begin(); 
Student s = new Student(); 
Student s2 = new Student();
Cat c = new Cat();
// this should be c.setStudents(s2)
c.getStudents().add(s2); 
em.persist(c); 
em.getTransaction().commit();

Honestly don't fully understand why you are trying to assign two student sets into cats, you should join both sets into one and then add them to cats.

You also may want to look into explicitly setting your fetch type, @ManyToMany(fetch = FetchType.LAZY) or FetchType.EAGER.

James McMahon
A: 

Perhaps a better example would have been:

em.getTransaction().begin(); 
Student s = new Student(); 
Student s2 = new Student(); 
Cat c = new Cat(); 
em.persist(s); 
em.persist(s2);
em.persist(c); 
c.getStudents().add(s); 
c.getStudents().add(s2); 
em.getTransaction().commit(); 

and then trying to say

Cat c2 = em.find(Cat.class,c.getYID());
Student s3 = em.find(Student.class,s.getXID());
System.out.println(c2.getYID() + ": " + c2.getStudents());
System.out.println(s3.getXID() + ": " + s3.getCats());

The above prints:

1: {[[Movie: movieID=2], [Movie: movieID=3]]}

2: {[]}

This makes no sense to me, since the cat with id=1 has a movie in its set with id=2, but the movie with id=2 does not have a cat in its set with id=1. (Changing the cascade type didn't seem to affect the results.)

Thanks so much for replying.

B.J.

Benny
It just seems that, based on the way the entities are set up, doing c = em.find(Cat.class,1) should give me a cat object with all the XID's from all the rows in the x_y table whose YID is 1. It should basically be like saying: c.setStudents(select XID from x_y where YID = 1;)
Benny
Benny, just as a heads up, in the future you probably want to edit your question to add clarification or additional information.
James McMahon
That is odd, my recommendation to you would be to try generating the classes from Netbeans (I'm sure eclipse can do this also) as opposed to hand rolling them. If that doesn't work, come back and post more information.
James McMahon