aspose file tools*
The moose likes Object Relational Mapping and the fly likes one to one mapping in hibernate..exception while saving. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one to one mapping in hibernate..exception while saving." Watch "one to one mapping in hibernate..exception while saving." New topic
Author

one to one mapping in hibernate..exception while saving.

vani venkat
Ranch Hand

Joined: Nov 21, 2006
Posts: 142
I have one to one relation between user and candidate. ideally user is used for authentication purposes and candidate holds all other information. i defined many to one relation in candidate hm file. when i try to save candidate bean, it gives lock wait time out exception. can some one point out what the problem is. i searched and could not get good infromation of solution for this.

Here are the hbm files.
User.hbm.xml


Candidate.hbm.xml


candidate.java

private User candidateUserId;
public User getCandidateUserId() {
return candidateUserId;
}

public void setCandidateUserId(User candidateUserId) {
this.candidateUserId = candidateUserId;
}




saving candidate bean in DAO.



SCJP 1.4, SCWCD 1.5
vani venkat
Ranch Hand

Joined: Nov 21, 2006
Posts: 142
I restarted Jboss server and here is the new exception.
is there anything wrong with mapping?

15:46:21,259 INFO [STDOUT] Hibernate: insert into CSS_User (userId, password, f
irstName, lastName) values (?, ?, ?, ?)
15:46:21,291 INFO [STDOUT] Hibernate: insert into css_candidate (firstName, las
tName, emailId, businessPhone, homePhone, cellPhone, street, apt, city, state, z
ip, country, createDate, modifiedDate, userId) values (?, ?, ?, ?, ?, ?, ?, ?, ?
, ?, ?, ?, ?, ?, ?)
15:46:21,291 WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1452, S
QLState: 23000
15:46:21,291 ERROR [org.hibernate.util.JDBCExceptionReporter] Cannot add or upda
te a child row: a foreign key constraint fails (`ssln`.`css_candidate`, CONSTRAI
NT `FK_Candidate_userId` FOREIGN KEY (`userId`) REFERENCES `css_user` (`userId`)
ON UPDATE CASCADE)

why is it not creating record in css_user table? should i save user too?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: one to one mapping in hibernate..exception while saving.