6 Replies Latest reply on Oct 4, 2006 6:31 PM by Monkey Den

    optional=true

    Monkey Den Master

      I'm trying to define a one-to-one bidirectional relationship in which one row may or may not exist. I thought setting optional=true (on both sides?) would allow for this but I get the following error:


      Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.xxx.entity.UserAlertsProfile#425195]


      Here is the code:

      @Entity
      @Name("userRecord")
      @Table(name = "RHTCONTACT")
      @Scope(ScopeType.SESSION)
      public class UserRecord implements IUserRecord, java.io.Serializable {
      
       /**
       * Retrieves the ContactKey from the entity
       */
       @Id
       @Length(max = 22)
       @Column(name = "CONTACT_KEY", length = 22, nullable = false)
       public Long getContactKey() {
       return this.contactKey;
       }
      
       /**
       * Sets the ContactKey of the entity
       */
       public void setContactKey(Long contactKey) {
       this.contactKey = contactKey;
       }
      
       /**
       * @return the alertsProfile
       */
       @OneToOne(optional=true, fetch=FetchType.EAGER)
       @JoinColumn(name="USER_KEY", unique=true, nullable=false, updatable=false, insertable=false)
       public UserAlertsProfile getAlertsProfile() {
       return alertsProfile;
       }
      
       /**
       * @param alertsProfile the alertsProfile to set
       */
       public void setAlertsProfile(UserAlertsProfile alertsProfile) {
       this.alertsProfile = alertsProfile;
       }
       ...
      }
      


      @Entity
      @Name("alertsprofile")
      @Table(name = "USER_PROFILE_ALERTS")
      public class UserAlertsProfile implements java.io.Serializable {
      
       /**
       * Retrieves the UserKey from the entity
       */
       @Id
       @Length(max = 22)
       @Column(name = "USER_KEY", length = 22, nullable = false)
       public Long getUserKey() {
       return this.userKey;
       }
      
       /**
       * Sets the UserKey of the entity
       */
       public void setUserKey(Long userKey) {
       this.userKey = userKey;
       }
      
       /**
       * @return the userRecord
       */
       @OneToOne(optional=true, mappedBy="accountInfo")
       public UserRecord getUserRecord() {
       return userRecord;
       }
      
       /**
       * @param userRecord the userRecord to set
       */
       public void setUserRecord(UserRecord userRecord) {
       this.userRecord = userRecord;
       }
      }


      Thanks for suggestions.