Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use a @JoinColumn instead of @Column to map relationship attribute ?

843830Sep 8 2009 — edited Sep 13 2009
Hello,

I wanted to create a bi-directional @OneToOne. The Verifier mandates that I use a @JoinColumn and not a @Column.

Is this true?

I am using Glassfish RI, the accompanying Java DB (Derby) and the oracle toplink essentials that comes with the j2ee sdk.

There was no problem with using a @Column when it was an Uni Directional relationship. When I declared the fields each other, there were problems.
@Entity
@Table (name = "ORGANIZATION")
public class Organization implements Serializable {

 	@Id
 	@GeneratedValue(strategy=GenerationType.AUTO)
 	@Column(name = "ORGANIZATIONID")
	private int organizationId;

	//Bi directional OneToOne
	@OneToOne(optional=true)
        @Column(name = "ADDRESS")
	private Address address;
@Entity
@Table (name = "ADDRESS")
public class Address implements Serializable {

    private int addressId;

    @Column (name="ORGANIZATION")
    @OneToOne(mappedBy="address", optional=true)
    private Organization getOrganization() {
		return this.organization;
	}
	private void setOrganization(Organization organization) {
		this.setOrganization(organization);
	}
Your help would be very useful.

Thanks in advance,
Rajesh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2009
Added on Sep 8 2009
4 comments
1,288 views