# Missing parameter during merge/persist operation to insert new entity

**URL:** <https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333>\
**Category:** Hibernate ORM\
**Created:** [September 3, 2018, 2:07pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333 "2018-09-03T14:07:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hugobtavares](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hugobtavares/32/193_2.png) [@hugobtavares](https://discourse.hibernate.org/u/hugobtavares)\
**Post date:** [September 3, 2018, 2:07pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/1 "2018-09-03T14:07:01Z")

</div>

Hi!

Already posted a similar question on Stackoverflow last week, but since then I’ve managed to change my implementation yet with no success so far.

Situation: I’m trying to persist/merge this entity, `newClassification`, of a type I called “`Classification`”, which has all the parameters filled in, except for “id” (see code below, please).  
This entity has its parameter `classicitationType` fully and correctly filled. This last one has its parameter `systemType` fully and correctly filled as well.

Tried both with `entityManager.persist( newClassification )` and `entityManager.merge( newClassification )` with the same result: the insert instruction that is being generated by Hibernate does not reflect all the parameters. E.g.: I get…

`c=o.h.SQL, m=logStatement, l=92, msg: insert into plat.classification_system (year, system, id) values (?, ?, ?)`

…when I was expecting something like…

`c=o.h.SQL, m=logStatement, l=92, msg: insert into plat.classification_system (year, class_type_guid, system, id) values (?, ?, ?, ?)`

My database model is as follows (omitted constraint definitions here, but if needed I’ll paste them):

```sql
create table classification_system (
 id number(19, 0) not null,
 year varchar2(255 char) not null,
 class_type_guid(48 char ) not null,
 system varchar2(255 char) not null,
 primary key (id)
)

create table class_type (
  guid (48 char) not null,
  code varchar2(255 char) not null,
  year varchar2(255 char) not null,
  system_type_guid varchar2(48 char) not null,

  primary key (guid, year)
)

create table system_type (
  guid (48 char ) not null,
  translation varchar2(255 char) not null,
  year varchar2(255 char) not null,
  primary key (guid, year)
)

```

And my Java classes are as follows:

```java
@Entity
@Table("classification_system", indexes = {
        @Index(name="CLASS_IDX1",columnList="ID"),
        @Index(name="CLASS_IDX2",columnList="ID, SYSTEM"),
        @Index(name="CLASS_IDX3",columnList="ID, CLASS_TYPE_GUID, SYSTEM")
})
class Classification extends ClassificationAbstract implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="classSeq")
    @SequenceGenerator(name="classSeq", sequenceName="CLASS_SEQ", allocationSize=1)
    private Long id;

    // couple of constructors...

    private String system;

    public Classification() {
        super();
    }

    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getSystem() {
        return this.system;
    }
    public void setSystem(String system) {
        this.system = system;
    }
}

@MappedSuperclass
public abstract class ClassificationAbstract implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(nullable = false)
    @NotNull
    private String year;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
        @JoinColumns(value = {
            @JoinColumn(name = "YEAR", referencedColumnName = "YEAR", insertable = false, updatable = false),
            @JoinColumn(name = "CLASS_TYPE_GUID", referencedColumnName = "GUID", insertable = false, updatable = false)
    })
    private ClassificationType classificationType;

    public ClassificationType getClassificationType() {
        return classificationType;
    }
    public void setClassificationType(ClassificationType classificationType) {
        this.classificationType = classificationType;
    }

}

@Entity
@Table(name="CLASS_TYPE", uniqueConstraints = 
        @UniqueConstraint(columnNames = {"YEAR", "GUID", "SYSTEM_TYPE_GUID"})
)
public class ClassificationType implements Serializable {
    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private ClassificationTypePK id;

    private String code;
    @Column(name = "YEAR", nullable = false)
    private String year;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "YEAR", referencedColumnName = "YEAR",
                insertable = false, updatable = false, nullable = false),
        @JoinColumn(name = "SYSTEM_TYPE_GUID", referencedColumnName = "GUID",
                insertable = false, updatable = false, nullable = false)
    })
    private SystemType systemType;

    public ClassificationTypePK getId() {
        return id;
    }
    public void setId(ClassificationTypePK id) {
        this.id = id;
    }
    public String getCode() {
        return this.code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getSystemType() {
        return this.systemType;
    }
    public void setSystemType(String systemType) {
        this.systemType = systemType;
    }
}

@Embeddable
public class ClassificationTypePK implements Serializable {
    private static final long serialVersionUID = 1L;

    private String guid;
    private String year;

    //getters + setters + hashCode + equals implementations...
}

@Entity
@Table(name="SYSTEM_TYPE", uniqueConstraints = 
        @UniqueConstraint(columnNames = {"YEAR", "GUID"})
)
public class SystemType implements Serializable {
    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private SystemTypePk id;

    private String translation;

    public SystemTypePk getId() {
        return id;
    }
    public void setId(SystemTypePk id) {
        this.id = id;
    }
    public String getTranslation() {
        return translation;
    }
    public void setTranslation(String translation) {
        this.translation = translation;
    }

    //hashCode + equals implementations...
}

@Embeddable
public class SystemTypePL implements Serializable {
    private static final long serialVersionUID = 1L;

    private String guid;
    private String year;

    //getters + setters + hashCode + equals implementations...
}

```

I’m presently working on a Oracle XE database with Java EE7 + Hibernate 5.0.9 (final).

Am I leaving something out? Or am I doing something that it is just not right?

---

<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:** [September 3, 2018, 2:22pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/2 "2018-09-03T14:22:36Z")

</div>

> [@hugobtavares](#):
>
> …when I was expecting something like…
> 
> `c=o.h.SQL, m=logStatement, l=92, msg: insert into plat.classification_system (year, guid, system, id) values (?, ?, ?, ?)`

Why were you expecting that since `classification_system` has no `guid` column?

---

<div class="post-metadata">

**Author:** ![hugobtavares](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hugobtavares/32/193_2.png) [@hugobtavares](https://discourse.hibernate.org/u/hugobtavares)\
**Post date:** [September 3, 2018, 3:37pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/3 "2018-09-03T15:37:50Z")

</div>

Sorry! What I meant was:

`c=o.h.SQL, m=logStatement, l=92, msg: insert into plat.classification_system (year, class_type_guid, system, id) values (?, ?, ?, ?)`

Already corrected in the original 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:** [September 3, 2018, 3:53pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/4 "2018-09-03T15:53:06Z")

</div>

That’s because you marked the `CLASS_TYPE_GUID` with ` insertable = false` and `updatable = false`.

> [@hugobtavares](#):
>
> @JoinColumn(name = “CLASS\_TYPE\_GUID”, referencedColumnName = “GUID”, insertable = false, updatable = false)

Probably you copy/pasted it from the YEAR mapping where it makes sense since you already mapped the `YEAR` column. Try removing those 2 attributes and it should work.

---

<div class="post-metadata">

**Author:** ![hugobtavares](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hugobtavares/32/193_2.png) [@hugobtavares](https://discourse.hibernate.org/u/hugobtavares)\
**Post date:** [September 3, 2018, 4:05pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/5 "2018-09-03T16:05:46Z")

</div>

I’ve tried that before, and when I compile I get

`...jpa-generate-hbmddl failed: Mixing insertable and non insertable columns in a property is not allowed: plat.Classification.classificationType`.

Other things I also tried:

- On `ClassificationType` + `CLASS_TYPE` table removed all references to `SystemType` + `SYSTEM_TYPE`, for fearing the “link” with the `year` attribute was causing the trouble and to isolate the issue. The issue persisted.
- On `Classification / ClassificationAbstract` type + `classification_system` table removed `year`. The `insert` instruction obviously does not include the `year` column now, and still does not include the `class_type_guid` column when actually the attribute `classificationType` is well formed.

---

<div class="post-metadata">

**Author:** ![hugobtavares](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hugobtavares/32/193_2.png) [@hugobtavares](https://discourse.hibernate.org/u/hugobtavares)\
**Post date:** [September 3, 2018, 4:48pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/6 "2018-09-03T16:48:23Z")

</div>

@vlad: I decided to remove the annotations `"insertable=false, updatable=false` on both JoinColumns and it is working fine now. Thank you so much for your helpful pointers.

It is working but I still have to revert the references to `SystemType` + `SYSTEM_TYPE` that I set to `@Transient` on `ClassificationType`. Will update once I have all this code up and running.

---

<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:** [September 3, 2018, 5:32pm UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/7 "2018-09-03T17:32:58Z")

</div>

You can move those attributes to the YEAR column instead.

---

<div class="post-metadata">

**Author:** ![hugobtavares](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/hugobtavares/32/193_2.png) [@hugobtavares](https://discourse.hibernate.org/u/hugobtavares)\
**Post date:** [September 4, 2018, 10:00am UTC](https://discourse.hibernate.org/t/missing-parameter-during-merge-persist-operation-to-insert-new-entity/1333/8 "2018-09-04T10:00:45Z")

</div>

OK, with everything integrated and working fine, let me tell you what I did, just for the purpose of sharing what I’ve learned:

- Removed `year` attribute from `ClassificationAbstract`, as well as the `insertable=false` and `updatable=false` annotations:

```java
@MappedSuperclass
public abstract class ClassificationAbstract implements Serializable {
    private static final long serialVersionUID = 1L;

    @ManyToOne(fetch = FetchType.EAGER, optional = false)
        @JoinColumns(value = {
            @JoinColumn(name = "YEAR", referencedColumnName = "YEAR", nullable = false),
            @JoinColumn(name = "CLASS_TYPE_GUID", referencedColumnName = "GUID", nullable = false)
    })
    private ClassificationType classificationType;

    public ClassificationType getClassificationType() {
        return classificationType;
    }
    public void setClassificationType(ClassificationType classificationType) {
        this.classificationType = classificationType;
    }
}

```

- Removed `.hashCode()` and `.equals()` definitions from `ClassificationType` and `SystemType` (I thought they sould be there…)

- Left `.hashCode()` and `.equals()` definitions from `ClassificationTypePK` and `SystemTypePK` (composite keys for `ClassificationType` and `SystemType`, respectively), as per @vlad article:([https://vladmihalcea.com/the-best-way-to-map-a-composite-primary-key-with-jpa-and-hibernate/](https://vladmihalcea.com/the-best-way-to-map-a-composite-primary-key-with-jpa-and-hibernate/)

(Thanks for all your pointers along the thread, @vlad! 🙂)
