users@glassfish.java.net

Re: Problem persiting child object

From: <glassfish_at_javadesktop.org>
Date: Fri, 26 Sep 2008 07:25:14 PDT

Hello,

You tried to map a int using ManytoOne which likely resulted in the exception. Instead of having an int school_student_FK, you seemed to map this field (in XML) indicating it should have been
  private School school;

The errors should have had nothing to do with the cascade option - infact, if you do not have a cascade persist on the school->student relation and studen't isn't directly persisted, I would expect you get an exception.

I would suggest you keep the cascade option and change your Student class' attribute to be a school type. In addition, when you add a Student to a School, you need to set the back pointer (the student needs to know what school they go to) otherwise the foreign key will not get set.

Best Regards,
Chris
[Message sent by forum member 'chris_delahunt' (chris_delahunt)]

http://forums.java.net/jive/thread.jspa?messageID=301830