[jboss-user] [EJB 3.0] - optional=true
monkeyden
do-not-reply at jboss.com
Wed Oct 4 16:05:12 EDT 2006
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.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976149#3976149
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976149
More information about the jboss-user
mailing list