This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Now when i attempt to Save GroupMember object by filling all member variable, Hibernate only does insertion for 3 column, one column fkgroup is not getting inserted.
insert into GroupMember (priority, gmid, cId) values (?, ?, ?)
I'm unable to save fkgroup column of GroupMember table, get following exception
SEVERE: SQL Anywhere Error -194: No primary key value for foreign key 'group' in table 'GroupMember' org.hibernate.exception.ConstraintViolationException: could not insert: [my.test.pkg.GroupMember]
Then i realized that insert="false" is set many-to-one relation which is causing issue for fkgroup not to be inserted. Setting insert="true" here gives exception
org.hibernate.MappingException: Repeated column in mapping for entity: my.test.pkg.GroupMember column: cId (should be mapped with insert="false" update="false")
For now, i have no idea how can insert GroupMember with fkgroup foreign key.
I have checked forum, but couldn't find any solution.
Any help on how can i insert/save GroupMember object ??
this sounds likes a similar issue we just had. Let me ask this question.
Is it that you have a composite ID with two fields, and one of those two fields is a FK to the Parent table/object?
If so this is our solution
That is the basic solution we had for this problem. There is stuff out there in the web in which I found this solution. And in older posts they had the Child class have a faked out property like
@Column(name="someId"
private Long parent
But that is only needed for older versions of Hibernate 3.x
In my case i have Composite Primary key and foreign key which is also composite key. Now one of the column is same
i.e. Table Group has composite Id PRIMARY KEY(gId, cId) [ Where cId is primary key of other table ]
Now Table GroupMember has composite primary key PRIMARY KEY(gmid, cId ) [ Where cId is primary key of other table ].
GroupMember also has foreign key fkgroup REFERENCES Group(gid, cId) (which is composite key as mentioned above]
Now, when i attemt to save GroupMember instance, foreign key (fkgroup) is not inserted. In many-to-one relationship i cannot set insert=true because cId is part of primary key for both GroupMember and Group Table.
How do i persist column fkgroup of GroupMemeber table?