posted 16 years ago
Hello Ranchers,
I have a question on Many to Many relationship.
Here's my system info.
Using Toplink Essentials JPA
Using Oracle 10g database.
Here's my scenario - * = pk and ** = fk
I use these following tables
User
* userId (using oracle sequence) not null
name
age
Group
* groupId (using oracle sequence) not null
groupName
UserGroup
* userGroupId (Using oracle sequence) not null
** userId
** groupId
I have created 2 Entities => User and Group
UserGroup table contains the Many to Many mapping between User and Group tables.
Here's my problem
When I try to persist the user entity after adding new groups I get a database exception ->
Cannot insert NULL into UserGroup.userGroupId
JPA generated insert statement is
INSERT INTO UserGroup(userId, groupId) values(?,?)
bind => (111,10)
As you can see there is no userGroupId in the insert statement generated by toplink engine.
The correct insert statement should have been
INSERT INTO UserGroup(userGroupId, userId, groupId) values(?,?,?)
bind => (seq.next_val, 111, 10)
Is there any way in JPA I can add an autogenerated column to the @JoinTable annotation?
The only option i see is to use a trigger, just wanted to know if it is possible to insert a value into a column not participating as one of the joincolumns.
[ November 07, 2007: Message edited by: Shailesh Kini ]