Hibernate activating Validator on Spring Hibernate project

263 views
Skip to first unread message

coderinabstract

unread,
Jul 5, 2012, 7:24:59 PM7/5/12
to gwt-val...@googlegroups.com
In a project with GWT UI and hibernate/Spring backend... we are not using hibernate validator to validate Entities as the validation needs to occur much before the database as there is service layer. A strange behavior was noticed that as soon as the dependency was added hibernate validation started kicking in and throwing NPEs which is undesired. As soon as I remove dependency from POM this goes away.

Any thoughts.. starting to experiment with library and this error shows hibernates BeanValidationEventListerner getting fired up. The Hibernate stuff withi its Entities is not annotated with any validation annotations and is not desired to be validated as validations happen in service layer with Dtos before each reaches hibernate Entities on the server side. The goal is to share the same validations in the api layer when creating DTO POJOs to be passed into services and GWT when passed over network from the User interfaces.

Also, will these POJOs with their annotations be able to be transformed into a REST api layer endpoint with e.g. Spring rest support?

Any thoughts... Cheers.

java.lang.NullPointerException

at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:131)

at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:94)

at org.hibernate.action.EntityIdentityInsertAction.preInsert(EntityIdentityInsertAction.java:160)

at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:65)

at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)

at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:320)

at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:203)

at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:129)

at org.hibernate.ejb.event.EJB3SaveOrUpdateEventListener.saveWithGeneratedId(EJB3SaveOrUpdateEventListener.java:62)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)

at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)

at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:685)

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:677)

at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:673)

coderinabstract

unread,
Jul 5, 2012, 9:58:46 PM7/5/12
to gwt-val...@googlegroups.com
OK.. disabled Hibernate validation listener for all server JPA entities by adding

 <validation-mode>NONE</validation-mode>

in persistence.xml persistence unit configuration... however now

validator.validate(DTO); call in GWT UI view object,

GWT ui is scanning all the JPA/hibernate entities and complaining about source not found for server side entities which we do not want to be enabled for validation and only want the DTOs which are in a shared package between client/server gwt style and we want to tell the validator to validate and which have the annotations.

Thoughts... Cheers.

coderinabstract

unread,
Jul 5, 2012, 10:24:59 PM7/5/12
to gwt-val...@googlegroups.com
Should have done more mining the groups before posting...

shows commandline option to specify the dto/model packages to scan.

Now got working on client.. need to run server side test...

Ok.. one comment for maintainability... we have many packages and would get challenged to put that in command line.. plus anyway some config file within the WAR can detect these as long as in classpath?

For production the entire tomcat/jetty type servers arguments would have to be manipulated and thats spreading the responsibility of the app outside the app and would really be clean if there was a convention of a fileName or something modular which could specify these models to be leveraged.. also aggregation from different pacakges e.g. one jar as some models, another jar has some models then their configs should be embedeble with those jars/modules vs wiring them at app level where app may not have knowledge of the jar domain encapsulation.... 

something like a ScanningModule Class which implements a interface or extends a framework class can be introspected or something like that...

unless I am missing something obvious.. which I have done enough today.
Thoughts...
Cheers
Reply all
Reply to author
Forward
0 new messages