[jboss-user] [JBoss Seam] - Problem with @OneToOne relations

madsph do-not-reply at jboss.com
Tue Sep 4 06:31:43 EDT 2007


In my application I have a one-to-one relation between my user entity and my address entity.

Addresses are loaded into the system from an external source, afterwards users are created manually and the correct address is then associated with the user.

My problem is that I am allowed to attach the same address to multiple users, without any problems saving the user entity. When trying to access the user again I get an error because the one-to-one relation has been violated. Is there a way to use annotations to ensure that the uniqueness is not violated so that I get a validation error when trying to persist or update my user entity, rather than having the application to fall apart because the datamodel was corrupted?

In my entity classes I have the following.
User:
  @OneToOne(optional = true)
  @JoinColumn(name = "address_id", nullable = true, unique = true)
  public Address getAddress()
  {
     return address;
  }

Address:
  @OneToOne(mappedBy = "address")
  public Xuser getXuser() {
    return xuser;
  }

  public void setXuser(Xuser xuser) {
    this.xuser = xuser;
  }

Thanks
Mads

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080802#4080802

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080802



More information about the jboss-user mailing list