Thanks tenwit for your reply.
I corrected what you said, but I think my main problem was I wasn't referencing the UserRole class at all in the java code. After reading P229 of HIA, I thought the CategoorizedItem class in the book's example was automatically being instantiated by Hibermate. Silly me
I changed the code to when creating a user to this:
Code:
UserRole userRole = new UserRole(role);
user.addUserRole(userRole); // add to set of userRoles
then persist it.
I changed the constructor to just take a role, as I didn't require a parent element in the mapping.
When I run the unit test now, I see a delete in the SQL and then another insert. Can't explain this:
Code:
Hibernate: select USR_SEQ.nextval from dual
Hibernate: insert into usr (row_ver_no, usr_nm, pwd_val, enbld_usr_fl, fst_nm, last_nm, cre_dtetm, upd_dtetm, cre_usr_id, upd_usr_id, usr_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update usr set row_ver_no=?, pwd_val=?, enbld_usr_fl=?, fst_nm=?, last_nm=?, cre_dtetm=?, upd_dtetm=?, cre_usr_id=?, upd_usr_id=? where usr_id=? and row_ver_no=?
Hibernate: insert into usr_role_xref (usr_id, role_id, cre_usr_id, cre_dtetm, row_ver_no) values (?, ?, ?, ?, ?)
Hibernate: update usr set row_ver_no=?, pwd_val=?, enbld_usr_fl=?, fst_nm=?, last_nm=?, cre_dtetm=?, upd_dtetm=?, cre_usr_id=?, upd_usr_id=? where usr_id=? and row_ver_no=?
Hibernate: delete from usr_role_xref where usr_id=? and role_id=? and cre_usr_id=? and cre_dtetm=? and row_ver_no=?
Hibernate: insert into usr_role_xref (usr_id, role_id, cre_usr_id, cre_dtetm, row_ver_no) values (?, ?, ?, ?, ?)
2006-05-30 16:21:16,353 [3756 ] [main] WARN org.hibernate.util.JDBCExceptionReporter (logExceptions) - SQL Error: 1, SQLState: 23000
2006-05-30 16:21:16,353 [3756 ] [main] ERROR org.hibernate.util.JDBCExceptionReporter (logExceptions) - ORA-00001: unique constraint (WW_SDC.PK_USR_ROLE_XREF) violated
2006-05-30 16:21:16,353 [3756 ] [main] WARN org.hibernate.util.JDBCExceptionReporter (logExceptions) - SQL Error: 1, SQLState: 23000
2006-05-30 16:21:16,353 [3756 ] [main] ERROR org.hibernate.util.JDBCExceptionReporter (logExceptions) - ORA-00001: unique constraint (WW_SDC.PK_USR_ROLE_XREF) violated
2006-05-30 16:21:16,353 [3756 ] [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener (performExecutions) - Could not synchronize database state with session
I'm only attempting to persist one user with one role
Any ideas?
Thanks