1

I have come to the same problem as in How to disable Hibernate validation in a Spring Boot project and done the same. In application.yml I have:

jsf:
  PROJECT_STAGE: Development
  primefaces:
    theme: overcast
logging:
  level:
    root: debug


spring:
  datasource:
    initialize: false
    password: heslo
    username: MoneyTracker
    url: jdbc:postgresql://localhost:5432/MT-test
  jpa:
    properties:
      javax:
        persistence:
          validation:
            mode: none
    hibernate:
      ddl-auto: update

So the validation mode should be set to none, but it looks like it is not. In log I can see:

2016-12-30 23:39:44.166  INFO 63192 --- [on(2)-127.0.0.1] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-12-30 23:39:44.215 DEBUG 63192 --- [on(2)-127.0.0.1] o.hibernate.jpa.internal.util.LogHelper  : PersistenceUnitInfo [
        name: default
        persistence provider classname: null
        classloader: ParallelWebappClassLoader
  context: ROOT
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@6d21714c

        excludeUnlistedClasses: true
        JTA datasource: null
        Non JTA datasource: org.apache.tomcat.jdbc.pool.DataSource@6798b962{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.postgresql.Driver; maxAct
ive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=
false; password=********; url=jdbc:postgresql://localhost:5432/MT-test; username=MoneyTracker; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=3000; accessToUnderlyingConnectionAllowed=t
rue; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=
false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; 
ignoreExceptionOnPreLoad=false; }
        Transaction type: RESOURCE_LOCAL
        PU root URL: file:/Users/romanrakus/Tomcats/apache-tomcat-8.5.4/webapps/ROOT/WEB-INF/lib/database-1.0-SNAPSHOT.jar
        Shared Cache Mode: UNSPECIFIED
        Validation Mode: AUTO
        Jar files URLs []
        Managed classes names [
                cz.romanrakus.moneytracker.db.entities.Person
                cz.romanrakus.moneytracker.db.entities.PersonRole
                cz.romanrakus.moneytracker.db.entities.SpendingType
                cz.romanrakus.moneytracker.db.entities.PredefinedCsvImport
                cz.romanrakus.moneytracker.db.entities.Spending]
        Mapping files names []
        Properties []

All settings are loaded correctly, but validation mode is not. Am I doing something wrong?

There is also a log lines about loading the validation mode property:

2016-12-30 23:50:01.534 DEBUG 63192 --- [on(7)-127.0.0.1] org.springframework.jndi.JndiTemplate    : Looking up JNDI object with name [java:comp/env/spring.jpa.properties.javax.persistence.validation.mode]
2016-12-30 23:50:01.534 DEBUG 63192 --- [on(7)-127.0.0.1] o.s.jndi.JndiLocatorDelegate             : Converted JNDI name [java:comp/env/spring.jpa.properties.javax.persistence.validation.mode] not found - trying original name [spring.jpa.properties.javax.persistence.validation.mode]. javax.naming.NameNotFoundException: Name [spring.jpa.properties.javax.persistence.validation.mode] is not bound in this Context. Unable to find [spring.jpa.properties.javax.persistence.validation.mode].
2016-12-30 23:50:01.534 DEBUG 63192 --- [on(7)-127.0.0.1] org.springframework.jndi.JndiTemplate    : Looking up JNDI object with name [spring.jpa.properties.javax.persistence.validation.mode]
2016-12-30 23:50:01.534 DEBUG 63192 --- [on(7)-127.0.0.1] o.s.jndi.JndiPropertySource              : JNDI lookup for name [spring.jpa.properties.javax.persistence.validation.mode] threw NamingException with message: Name [spring.jpa.properties.javax.persistence.validation.mode] is not bound in this Context. Unable to find [spring.jpa.properties.javax.persistence.validation.mode].. Returning null.
2016-12-30 23:50:01.534 DEBUG 63192 --- [on(7)-127.0.0.1] o.s.c.e.PropertySourcesPropertyResolver  : Found key 'spring.jpa.properties.javax.persistence.validation.mode' in [applicationConfigurationProperties] with type [String]

Why is validation mode still set to AUTO? What else I can do to have validator class with injected beans from spring?

UPDATE

During debugging I found out that validation mode is correctly parsed and set (even though in the log is something else). But still the application is using hibernate validator instead of spring validator. I have also figured property javax.persistence.validation.factory to contain reference to my Bean named validator. But still no luck :(

I'm using WebSecurityConfigurerAdapter, I don't know if it matters.

Community
  • 1
  • 1
Roman Rakus
  • 31
  • 1
  • 2
  • 7
  • I don't think your yam is valid. The key of the property is "javax.validation.persistent.mode" but you've created 4 nested object there (one for each word in the key). It's definnitely not going to set a property with that ID. – Stephane Nicoll Dec 31 '16 at 10:13
  • @StephaneNicoll Thank you for your comment. The correct property name is `javax.persistence.validation.mode`. When I try to change nested objects to one object in dotted notation, it make no change. Still the `AUTO` validation mode. I have also tried to set some invalid value (like `invalid`) and it won't start with exception (`org.hibernate.HibernateException: Unknown validation mode in javax.persistence.validation.mode: invalid`). So the nested notation AND dotted notation works the same. – Roman Rakus Dec 31 '16 at 11:22
  • It turned out that I had very different problem. I had to add validator (spring constraint validator) to JSF. The solution which works for me is at http://stackoverflow.com/a/21279420/5788897 – Roman Rakus Jan 17 '17 at 22:13

1 Answers1

0

It turned out that I had very different problem. I had to add validator (spring constraint validator) to JSF. The solution which works for me is at stackoverflow.com/a/21279420/5788897

Nicomedes E.
  • 1,326
  • 5
  • 18
  • 27
Roman Rakus
  • 31
  • 1
  • 2
  • 7