Hi everyone. This one's been a thorn in the side for quite some time, so any help (or pointers to a good book! JP with Hibernate isn't doing it for me) would be really appreciated.
Hibernate v.3.2.1 GA.
Code:
@ManyToMany
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name="QuestionGroup_Question",
joinColumns={@JoinColumn(name="QGROUPNAME_ID", referencedColumnName="id", unique=false)},
inverseJoinColumns={@JoinColumn(name="Q_ID", referencedColumnName="id", unique=false)}
)
@IndexColumn(name="ORDER_IDX", base=1)
List<Question> questions = new ArrayList<Question>();
The problem is, this is the generated MySQL schema:
Code:
mysql> describe QuestionGroup_Question ;
+---------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------+------+-----+---------+-------+
| QGROUPNAME_ID | bigint(20) | NO | PRI | | |
| Q_ID | bigint(20) | NO | UNI | | |
| ORDER_IDX | int(11) | NO | PRI | | |
+---------------+------------+------+-----+---------+-------+
3 rows in set (0.03 sec)
Specifically, Q_ID has to be unique!! It's essentially a many-to-one, and I don't know what's causing it.
Does anyone see anything wrong with my annotations? Or is there something else I should add? Is there another way to specified an ordered many-to-many that's worked for anyone?
Any help would be
really appreciated. Thanks in advance!