4 Replies Latest reply on Feb 6, 2009 1:32 PM by hardaur

    Silly question - persisting child objects

    hardaur
      I have 2 classes, a contest, and a prize.  A contest has a one to many relationship to prize.

      In the view, I'm instantiating (but NOT persisting) prizes and adding them to the contest.  When the user calls the save action I call entityManager.persist(contest).  This works correctly, saving the contest, and the prizes. . .however, the prizes do not have the FK back to contest (contest_id).

      Contest:
              @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "contest")
              public Set<Prize> getPrizes() {
                      return this.prizes;
              }


      Prize:
              @ManyToOne(fetch = FetchType.LAZY)
              @JoinColumn(name = "contest_id")
              public Contest getContest() {
                      return this.contest;
              }

      Any pointers on why this is happening?  I'm sure it's something silly, but after 2ish hours with google I'm finding nothing.

      Thanks!

      Gerald