Hi,
I tried using the cascase="all" option, and now i am getting the following exception:
Code:
org.springframework.orm.hibernate3.HibernateSystemException: attempted to assign id from null one-to-one property: userObj
This exception is coming because, the UserAddress class has a property of "User" class with get and setter methods, but the object is not initialized.
I tried making the property to be initiatlized, but when i tried to deploy it on the server, it is giving error.
Can somebody tell me how a one-to-one mapping can be done.
here are my classes:
Code:
public class User {
private int userID;
private String firstName;
private String middleInitial;
private String lastName;
private UserAddress userAddress = new UserAddress();
private UserContInfo userContInfo = new UserContInfo();
public User(){
}
/**
* @return Returns the firstName.
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName The firstName to set.
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return Returns the lastName.
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName The lastName to set.
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return Returns the middleInitial.
*/
public String getMiddleInitial() {
return middleInitial;
}
/**
* @param middleInitial The middleInitial to set.
*/
public void setMiddleInitial(String middleInitial) {
this.middleInitial = middleInitial;
}
/**
* @return Returns the userID.
*/
public int getUserID() {
return userID;
}
/**
* @param userID The userID to set.
*/
public void setUserID(int userID) {
this.userID = userID;
}
/**
* @return Returns the userAddress.
*/
public UserAddress getUserAddress() {
return userAddress;
}
/**
* @param userAddress The userAddress to set.
*/
public void setUserAddress(UserAddress userAddress) {
this.userAddress = userAddress;
}
/**
* @return the userContInfo
*/
public UserContInfo getUserContInfo() {
return userContInfo;
}
/**
* @param userContInfo the userContInfo to set
*/
public void setUserContInfo(UserContInfo userContInfo) {
this.userContInfo = userContInfo;
}
}
Code:
public class UserAddress {
private int userID;
private String address1;
private String address2;
private String cityName;
private String state;
private String country;
private String zipCode;
private User userObj;
//private UserAddressCompositeKey userAddressCompKey;
public UserAddress(){
}
/**
* @return Returns the addressLine1.
*/
public String getAddress1() {
return address1;
}
/**
* @param addressLine1 The addressLine1 to set.
*/
public void setAddress1(String address1) {
this.address1 = address1;
}
/**
* @return Returns the addressLine2.
*/
public String getAddress2() {
return address2;
}
/**
* @param addressLine2 The addressLine2 to set.
*/
public void setAddress2(String address2) {
this.address2 = address2;
}
/**
* @return Returns the cityName.
*/
public String getCityName() {
return cityName;
}
/**
* @param cityName The cityName to set.
*/
public void setCityName(String cityName) {
this.cityName = cityName;
}
/**
* @return Returns the country
*/
public String getCountry() {
return country;
}
/**
* @param country The country to set.
*/
public void setCountry(String country) {
this.country = country;
}
/**
* @return Returns the stateProvince.
*/
public String getState() {
return state;
}
/**
* @param State The State to set.
*/
public void setState(String state) {
this.state = state;
}
/**
* @return Returns the userID.
*/
public int getUserID() {
return userID;
}
/**
* @param userID The userID to set.
*/
public void setUserID(int userID) {
this.userID = userID;
}
/**
* @return Returns the zipCode.
*/
public String getZipCode() {
return zipCode;
}
/**
* @param zipCode The zipCode to set.
*/
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
/**
* @return the userObj
*/
public User getUserObj() {
return userObj;
}
/**
* @param userObj the userObj to set
*/
public void setUserObj(User userObj) {
this.userObj = userObj;
}
}
Thanks in advance.