persistence@glassfish.java.net

Persisting ManyToMany relationship error

From: Michael Smith <michaelsmith3861_at_sbcglobal.net>
Date: Thu, 23 Aug 2007 22:39:20 -0700 (PDT)

                         This is probably a beginner question, but here goes. I have an entity that has a ManyToMany relationship between Schedule and Venue, with both having a parent Table of Employer. The Tables including the Join table are created fine and I could populate the Employer and Venue Tables fine, but when I create the Schedule object and the object is sent off to be persisted:
 
      Schedule schedule = new Schedule(employer);
List<Venue> venueList = new ArrayList();
venueList = employer.getVenueList();
schedule.setListVenue(venueList);
sendMessage(schedule);
   it throws the following error:
   Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that lazy relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.
 
 and keeps ramming the transaction through and clogging the Schedule table with junk, and not persisting anything in the Join table. It seems that passing the venue collection to the entity should instantiate the relationship. Similar OneToMany relationships work fine. I'm using Netbeans 5.5.1, Struts, EJB 3.0, glassfish, mysql, and Toplink for the persistence unit.