Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation doesn't work on EntityManager.merge()

I have few validations on my entity, like @NotNull, and some generation, like

@Id
@GeneratedValue(strategy = AUTO)
@Column(name = "ID")
private Long id;

@Column
@GeneratedValue(strategy = GenerationType.AUTO)
private Long referenceNumber;

However when calling EntityManager.merge() this values are not generated. Null fields with @NotNull annotation are passed without any complain. Even id is not generated.

Should I switch this generation on somehow? How, and where?

like image 459
amorfis Avatar asked Oct 15 '25 14:10

amorfis


1 Answers

Merge() does not invoke pre-insert/pre-update event listeners by default. flush() after the merge() should do it.

like image 53
kraftan Avatar answered Oct 17 '25 05:10

kraftan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!