# Hibernate @SecondaryTable() for both Parent and Child with the same name

**URL:** <https://discourse.hibernate.org/t/hibernate-secondarytable-for-both-parent-and-child-with-the-same-name/3562>\
**Category:** Hibernate ORM\
**Created:** [December 20, 2019, 11:03am UTC](https://discourse.hibernate.org/t/hibernate-secondarytable-for-both-parent-and-child-with-the-same-name/3562 "2019-12-20T11:03:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arungm20](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/arungm20/32/899_2.png) [@arungm20](https://discourse.hibernate.org/u/arungm20)\
**Post date:** [December 20, 2019, 11:03am UTC](https://discourse.hibernate.org/t/hibernate-secondarytable-for-both-parent-and-child-with-the-same-name/3562/1 "2019-12-20T11:03:28Z")

</div>

We have a requirement to insert to DB using Hibernate which has a Data model as below

```auto
@javax.persistence.Entity(name = "table1")
@SecondaryTable(name = "table2", pkJoinColumns = @PrimaryKeyJoinColumn(name = "fk2ObjId", referencedColumnName = "object_id"))
public class Parent {

}

@SecondaryTable(name = "table2", pkJoinColumns = @PrimaryKeyJoinColumn(name = "fk2ObjId", referencedColumnName = "object_id"))
public class Child extends Parent {

   @ManyToOne(optional = true, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, fetch = FetchType.LAZY)
   @JoinColumn(table = "table2", name = "fk2RefId", nullable = true)
   private Reference reference = null;
}

```

Now when I try to insert data to `table2` , I see insert statements as below

1. insert into table1 – from Parent class
2. insert into table2 – from Parent class
3. insert into table2 – from child class

Unfortunately, as the `fk2ObjId` is the primary key, the insert at 2 and 3 will conflict for unique constraint violation which is obvious

Question: How let Child class know not to generate another insert statement and update the existing one?
