Thursday, September 26, 2013

Re: GWT Requestfactory JSR-303 Problems when updating entity

Dear Thomas,

Following your text, this is exactly how I would expect Validation to behave.

But, let me explain you my problem a little bit in more detail:
In my case validation works fine when creating a entirely new entity. (PRE-PERSIST works just fine.)

Validation does not work properly when editing an existing entity e.g. on client side "entityEdited = request.edit(sampleEntity);" followed by calling update() method on server.
In case of an edited entity, which contains a wrong parameter that should cause a constraint violation .... GWT validates it .... than it throws the ConstraintViolationException which you can see below (this is what I would expect because the entity is not valid) .... but instead of calling onConstraintViolations() method on clients callback object, it calls onFailure() method ... (and this is not what I would expect).

As previously mentioned, this behavior occur only in case of edited entities.

Question: What could be the reason for GWT treating the ConstraintViolationException as on ordinary Exception in case an edited entity sent to server using RequestFactory?
This is not how it should be .... Right?

BTW: The service method is never called!

Thank you in advance:

Nermin


Am Mittwoch, 25. September 2013 19:18:38 UTC+2 schrieb Thomas Broyer:
RequestFactory validates domain objects after it deserialized them but before it calls your service methods. If they fail validation, service methods are not called and onConstraintViolations is called on the client-side (and the proxies and request context are unfrozen so you could fix things and resubmit). Any exception throw from within a service method results in onFailure to be called on the client-side for the Request corresponding to the service method.

So the question is: why validation fails on pre-persist but on from RequestValidation? (could be validation groups, could depend on the state of the DB –e.g. unique constraints–, etc.)

On Wednesday, September 25, 2013 1:19:54 PM UTC+2, Nermin wrote:
Dear Group,

I am using GWT Requestfactory for accessing server-side entities (JPA entities).
For validating data I apply JSR 303 validation.

Here is my situation:
1. On Persist everything works fine. Entity is validated on pre-persit and in case of constraint violations the "onConstraintViolation(..)" is called.
Persisting entities works fine.

2. Problem occurs when I try to edit an existing entity using  "entity2 = request.edit(sampleEntity);", write new data to it and send it to the server.
In that case a ConstraintViolation is thrown (probably this should be the case) but "onFailure(...)" method is called .... instead of the "onConstraintViolation(..)"?

What could be the reason for this??? Why is the "onConstraintViolation(..)" not called when updating the entity?
The error message is displayed below:

Thank you in advance:

Nermin


javax.validation.ConstraintViolationException: Validation failed for com.emajstor.server.persistence.PrivatePerson@2b85ffb8 during pre-update for groups [interface javax.validation.groups.Default] - exceptions are attached
    at org.datanucleus.validation.BeanValidatorHandler.validate(BeanValidatorHandler.java:71)
    at org.datanucleus.validation.BeanValidatorHandler.preStore(BeanValidatorHandler.java:86)
    at org.datanucleus.api.jpa.JPACallbackHandler.preStore(JPACallbackHandler.java:102)
    at org.datanucleus.state.JDOStateManager.flush(JDOStateManager.java:3827)
    at org.datanucleus.ObjectManagerImpl.flushInternalWithOrdering(ObjectManagerImpl.java:3888)
    at org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:3811)
    at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:3751)
    at org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:4141)
    at org.datanucleus.ObjectManagerImpl.transactionPreCommit(ObjectManagerImpl.java:428)
    at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:398)
    at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:287)
    at org.datanucleus.ObjectManagerImpl.close(ObjectManagerImpl.java:1090)
    at org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:193)
    at com.emajstor.server.AppHandlerFilter.doFilter(AppHandlerFilter.java:91)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectRequest(DevAppServerServersFilter.java:369)
    at com.google.appengine.tools.development.DevAppServerServersFilter.doDirectServerRequest(DevAppServerServersFilter.java:352)
    at com.google.appengine.tools.development.DevAppServerServersFilter.doFilter(DevAppServerServersFilter.java:115)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:97)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:480)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment