Validation does not work on EntityManager.merge ()

I have some checks on my object 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() these values ​​are not generated. Zero fields annotated with @NotNull are transmitted without any complaints. Even id not generated.

Should I somehow switch this generation? How and where?

+3
source share
2 answers

In addition to kraftan's answer:

  • By default, automatic bean authentication in JPA 2.0 works if the authentication provider is "present in the environment", otherwise it silently works. You can add

     <validation-mode>CALLBACK</validation-mode> 

    before persistence.xml to generate an error if the verification provider is not found.

  • JPA does not support the generation of arbitrary (non-id) properties. Some JPA providers may have extensions .
+1
source

Merge() does not by default call pre-insert / pre-update event listeners. flush() after Merge() has to do this.

+6
source

Source: https://habr.com/ru/post/1410982/


All Articles