-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Difficulties with a one-to-many mapping
PostPosted: Mon Apr 12, 2010 1:07 pm 
Newbie

Joined: Mon Apr 12, 2010 12:58 pm
Posts: 1
Hi,

I'm struggling to succcessfully achieve a one-to-many mapping.

The "one" side is a class called GradingForm, which contains a list of Answer objects. I'm trying to map this using a join table.

The relevant portion of my GradingForm class is:

Code:
public class GradingForm implements Grading, Serializable,
      Comparable<GradingForm> {

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue
   @Column(name = "GradingID")
   private int gradingID;

   @OneToMany(cascade = CascadeType.ALL)
   @JoinTable(name = "gradinganswers", joinColumns = @JoinColumn(name = "gradingID", unique = true), inverseJoinColumns = @JoinColumn(name = "answerId"))
   private List<Answer> answers;


The Answer class is

Code:
public class Answer implements Serializable {

   private static final long serialVersionUID = 1L;

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "AnswerID")
   private int answerId;

   @Column(name = "GradingID")
   private boolean gradingID = false;


My questions are:

1) The columns referenced within the JoinTable statement are the Java instance variables - this should be the join table columns instead, right?

2) Is there anything I'm missing? My code does persist the items (when I change the stuff in Question 1), but does not seem to add the id of the GradingForm into the correct column of the join table.

Any & all help appreciated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.