Greetings!
Sometimes I have a NULL
value for FK in my child table.
So when I try to fetch this row from the parent table I receive this exception:
java.lang.IllegalArgumentException: Can not set int field com.tsum.entity.Photo.id to **null** value
I tried to use @NotFound
but for @JoinColumns
it does not work.
Child Entity:
@ManyToOne
@NotFound ( action = NotFoundAction.IGNORE )
@JoinColumns({
@JoinColumn(name = "desktop_image_id", referencedColumnName = "id"),
@JoinColumn(name = "mobile_image_id", referencedColumnName = "id"),
@JoinColumn(name = "tablet_image_id", referencedColumnName = "id")
})
private Photo photo;
Parent Entity:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private int id;
But, for example, when I use this construction for @JoinColumn it works fine:
@ManyToOne
@NotFound ( action = NotFoundAction.IGNORE )
@JoinColumn(name = "desktop_image_id", referencedColumnName = "id")
private Photo photo;
For temporary workaround I replace type for parent Id from int
to Integer
and it works fine for now:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Integer id;
Please, can anybody explain why this may happen?