Validation doesn't work on EntityManager.merge()

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

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

@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?


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


    to persistence.xml in order to generate an error if validation provider is not found.

  • JPA doesn't support generation of arbitrary (non-id) properties. Some JPA providers may have extensions.

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

Need Your Help

Replicating convenience implementations in Swift

ios objective-c swift instance-methods convenience-methods

I am attempting to understand the following code and how you would convert it to Swift. Specifically, I understand this adds an instance method you can call on an instance of CIImage. My question i...

Chrome input and text area padding sucks

css google-chrome input textarea

What the hell is that? I found there is some problem with padding in chrome with this elements but even if set the padding to 0 in both (textarea and input) they are not "looking same" width in chr...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.