Validation does not work with saving

I am building a web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with the Hibernate provider. The application runs on Tomcat 6.X.

I use bean validation in my entities. Hibernate Validator - provider, version 4.2.0.Final.

@NotEmpty(message="{site.checklangs}") @OrderBy("position ASC") @OneToMany(mappedBy = "site", fetch = FetchType.EAGER, cascade= CascadeType.ALL, orphanRemoval=true) private List<SiteLanguage> langs; 

@NotEmpty works persist , but not for merge

 @Override @Transactional public Site updateSite(Site site) { return entityManager.merge(site); } 

This throws exceptions when my list is empty. What for? How to fix it?

+4
source share
1 answer

Try calling entityManager.flush(); after merge() ;

See Validation does not work in EntityManager.merge () as a reference.

0
source

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


All Articles