0

I have a class configuration something like the following(just a sample not actual meaning) -

public class payment
{
    @Id
    @Column("payment_id")
    private int paymentId;

    @ManyToOne
    @JoinColumn(name ="")
    private Fine fine;
    //getter setter and other stuff
}

public class Fine{
    @Id
    @Column("fine_id")
    private int fineId;

    @Column("amount")
    private int fineAmount;

    //other stuff
} 

I am getting org.hibernate.ObjectNotFoundException: No row with the given identifier exists error message. In accordance with the answer it is because a foreign key cannot have null value but my db contains null. I cant change the db or project structure so is there any way so that i can issue null value to my foreign key 'legally' ie without creating an exception.

monster
  • 808
  • 10
  • 23

1 Answers1

0

Using @Column(nulable = true)

Is used for creation of DDL scripts and does not bring the desired behavior.

You need to mark the @ManyToOne as optional.

@ManyToOne(optional = true)
Sklo
  • 51
  • 4