# One To One Association strategy

**URL:** <https://discourse.hibernate.org/t/one-to-one-association-strategy/4020>\
**Category:** Hibernate ORM\
**Created:** [April 14, 2020, 10:07am UTC](https://discourse.hibernate.org/t/one-to-one-association-strategy/4020 "2020-04-14T10:07:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skhandu](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/skhandu/32/337_2.png) [@skhandu](https://discourse.hibernate.org/u/skhandu)\
**Post date:** [April 14, 2020, 10:07am UTC](https://discourse.hibernate.org/t/one-to-one-association-strategy/4020/1 "2020-04-14T10:07:55Z")

</div>

Hi All, In one to one mapping is it ok to add column foreign key in parent like

```auto
@Entity(name = "Post")
@Table(name = "post")
public class Post {

	@Id
	@GeneratedValue
	private Long id;

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "postDetails_id")
	private PostDetails postDetails;
}

```

```auto
@Entity(name = "PostDetails")
@Table(name = "post_details")
public class PostDetails {

	@Id
	@GeneratedValue
	private Long id;

	@OneToOne(mappedBy = "postDetails")
	private Post post;
}

```

Rather then  
Setting foreign key in post\_details table (i.e post\_id)

```auto
@Entity(name = "PostDetails")
@Table(name = "post_details")
public class PostDetails {
 
    @Id
    @GeneratedValue
    private Long id;

 
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "post_id")
    private Post post;
 
  
 
    
}

```

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [April 14, 2020, 11:18am UTC](https://discourse.hibernate.org/t/one-to-one-association-strategy/4020/2 "2020-04-14T11:18:19Z")

</div>

That’s not really a one-to-one association, but a many-to-one with a unique constraint.

Check out [this article](https://vladmihalcea.com/database-table-relationships/) for more details about how a one-to-one table relationship works.

Also, check out [this article](https://vladmihalcea.com/the-best-way-to-map-a-onetoone-relationship-with-jpa-and-hibernate/) to learn the best way you could map that with JPA and Hibernate.

Now, back to your question:

> is it ok to add column foreign key in parent like

No, it’s not. It’s a bad idea as it creates a circular dependency.

---

<div class="post-metadata">

**Author:** ![skhandu](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/skhandu/32/337_2.png) [@skhandu](https://discourse.hibernate.org/u/skhandu)\
**Post date:** [April 14, 2020, 12:10pm UTC](https://discourse.hibernate.org/t/one-to-one-association-strategy/4020/3 "2020-04-14T12:10:52Z")

</div>

Thank you Vlad  
So what i understood from that mapping is it’s good to add FK in child.

Thank You  
Salman
