NPE when used with Spring 3.05 and Hibernate 4.2

99 views
Skip to first unread message

Reto

unread,
Apr 1, 2012, 2:16:56 PM4/1/12
to gwt-validation
Hi,

We want to use gwt-validation 2.0 with Spring 3.0.5 and Hibernate 4.2.
When I add the gwt-validation 2.0 dependency to the project, I get an
error on the server-side (see below).

I have not used any javax.validation Annotations yet.
-> Is there some configuration possible, to make gwt-validation work
in this setup?
-> It seems that gwt-validation is used as default validation provider
- is this intended? If not, would it be okay to use hibernate
validation only?

Best regards,
Reto



2012-03-30 09:41:32,758 | Thread-6 | | WARN |
TypeSafeActivator | Unable to apply constraints on
DDL for <our domain package>.Workflow
java.lang.NullPointerException
at
com.em.validation.rebind.resolve.PropertyResolver.resolve(PropertyResolver.java:
108)
at
com.em.validation.rebind.resolve.PropertyResolver.getPropertyMetadata(PropertyResolver.java:
62)
at
com.em.validation.rebind.reflector.RuntimeReflectorImpl.<init>(RuntimeReflectorImpl.java:
64)
at
com.em.validation.rebind.reflector.factory.RuntimeReflectorFactory.getReflector(RuntimeReflectorFactory.java:
54)
at
com.em.validation.client.reflector.ReflectorFactory.getReflector(ReflectorFactory.java:
40)
at
com.em.validation.client.metadata.factory.DescriptorFactory.getBeanDescriptor(DescriptorFactory.java:
97)
at
com.em.validation.client.CoreValidatorImpl.getConstraintsForClass(CoreValidatorImpl.java:
366)
at
com.em.validation.client.ValidatorImpl.getConstraintsForClass(ValidatorImpl.java:
113)
at
org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:
142)
at
org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:
128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:
118)
at
org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:
1704)

Reto

unread,
Apr 3, 2012, 11:38:20 AM4/3/12
to gwt-validation
Hi all,

I have got some feedback and it works now for me with Spring and
Hibernate Validation on both client and server.
There are two options..

Option 1: Use of Hibernate Validation on the server and GWT
Validation on the client

Add gwt-validation to the pom.xml with scope 'provided' to exclude it
from the server deployment. This way, it won't be activated by Spring.
Also add hibernate-validation for the server.
<dependency>
<groupId>com.googlecode.gwt-validation</groupId>
<artifactId>gwt-validation</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>

Add gwt validation to your gwt.xml
<inherits name='com.em.validation.Validation' />

Disable Hibernate Validation on the client side. In the DevMode, in
the launch configuration, provide the following VM arguments:
-Dgwt.validation.excluded.ValidatorClassesRegexp=^(org.hibernate.*)|
(com.yourpackage.*?YourGWTIncompatibleValidator)

Provide the same VM argument when you do a GWT compile. You can do
that in the Advanced options tab in the GWT compile dialog.

If you do a maven build, exclude Hibernate Validation from the gwt-
maven-plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<executions>
<execution>
<configuration>
<extraJvmArgs>-Xmx512M -Xss512k -
Dgwt.validation.excluded.ValidatorClassesRegexp=^(org.hibernate.*)|
(com.yourpackage.*?YourGWTIncompatibleValidator)</extraJvmArgs>
<compileSourcesArtifact>org.hibernate:hibernate-
validator</compileSourcesArtifact>
</configuration>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
...

___________________________________________________________________________

Option 2: Disable Hibernate Validation and only use GWT validation
(for those who can..)

Use the following configuration in spring to disable validation,

<property name="hibernateProperties">
<props>
.......
<prop key="javax.persistence.validation.mode">none</prop>
</props>
</property>

chris.r

unread,
Apr 4, 2012, 11:37:48 AM4/4/12
to gwt-validation
Thank you so much for putting this out there.

I wanted to comment that as soon as I get some free time I'll be
redesigning the class scanning portions a little bit. Those should
only be needed for the GWT side. I was under the misapprehension that
the framework needed to identify all validators by type and
annotation. It is only required to do this for the built-in
annotations! Any other type should throw a ValidationException (iirc)
if a validatedBy class is not listed.

This will go a long way towards making gwt-validation container
agnostic (and slightly more JSR-303 compliant) on the container side.

-Chris

Marcel Stör

unread,
Apr 12, 2012, 10:34:20 AM4/12/12
to gwt-val...@googlegroups.com
This is great stuff. Actually, I think the described setup is actually a pretty common scenario - not something exceptional. Do you think you could turn this into a wiki page on Google Code?

Cheers,
Marcel
Reply all
Reply to author
Forward
Message has been deleted
0 new messages