Caused by: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property

35 Views Asked by At

I'm trying to insert values to JVCommitProperty Table but getting the "Caused by: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property [com.dev.neo.models.JVCommit.jvCommitProperty]" error

These are my two bean classes JVCommit and JVCommitProperty respectively:

@Entity
@Table(name = "JV_COMMIT")
public class JVCommit {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "jv_commit_pk_seq")
    @SequenceGenerator(name="jv_commit_pk_seq", sequenceName = "JV_COMMIT_PK_SEQ")
    @Column(name= "COMMIT_PK" , insertable = true, updatable = false)
    private long id;

    @MapsId
    @OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name= "COMMIT_FK" )
    private JVCommitProperty jvCommitProperty;
@Entity
@Table(name = "JV_COMMIT_PROPERTY")
public class JVCommitProperty {
    
    @Id
    @Column(name = "COMMIT_FK")
    private long id;
    
    @OneToOne(cascade=CascadeType.ALL,mappedBy="jvCommitProperty",fetch=FetchType.EAGER)
    private JVCommit jvCommit;

The code which i have wriiten in Service class is

//inserting data into JV_COMMIT table
                    JVCommit jvCommit = new JVCommit();
                    jvCommitRepository.save(jvCommit);
                    
                    //inserting data into JV_COMMIT_PROPERTY table
                    JVCommitProperty jvCommitProperty = new JVCommitProperty();
                    jvCommitProperty.setJvCommit(jvCommit);
                    jvCommitPropertyRepository.save(jvCommitProperty);

The Model between these two tables is given below: enter image description here

I have tried to set the jvCommit.setJvCommitProperty(jvCommitProperty);

0

There are 0 best solutions below