Reputation: 15770
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?
Upvotes: 4
Views: 1362
Reputation: 242686
In addition to kraftan's answer:
By default automatic bean validation in JPA 2.0 works if validation provider is "present in the environment", otherwise it silently doesn't work. You can add
<validation-mode>CALLBACK</validation-mode>
to persistence.xml
in order to generate an error if validation provider is not found.
Upvotes: 1
Reputation: 6312
Merge()
does not invoke pre-insert/pre-update event listeners by default. flush()
after the merge()
should do it.
Upvotes: 7