-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: JPATraversableResolver fails on annotated field
PostPosted: Wed May 12, 2010 5:16 pm 
Newbie

Joined: Wed May 12, 2010 4:55 pm
Posts: 2
Hi,

I have a class that has a field annotated with @NotNull. There is no no get-method for that field. Using Hibernate Validations (4.0.2 or 4.1.0.Beta) this worked fine. Now I've added Hibernate EntityManager 3.5.1 (including dependencies) to the classpath. Using the same code as before (including the creation of the ValidatorFactory and Validator) I now get the following exception:

Code:
Exception in thread "main" javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
   at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:773)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
   at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
   at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:213)
   at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
   at validationtest.ValidationTest.main(ValidationTest.java:19)
Caused by: javax.persistence.PersistenceException: Unable to find field or method: class validationtest.Person#identifier
   at org.hibernate.ejb.util.PersistenceUtilHelper.get(PersistenceUtilHelper.java:95)
   at org.hibernate.ejb.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:76)
   at org.hibernate.ejb.HibernatePersistence$1.isLoadedWithReference(HibernatePersistence.java:92)
   at javax.persistence.Persistence$1.isLoaded(Persistence.java:83)
   at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)
   at org.hibernate.validator.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:112)
   at org.hibernate.validator.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:47)
   at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:764)
   ... 6 more


When I add a get-method to the class it works well again.

After re-reading the Bean Validation Spec I'm not sure if this is a bug or if it is required to have a get-method even when using field access strategy. Any hints?

Thanks,
Nils


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Thu May 13, 2010 4:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

from the BV spec point of view not having a getter is not an issue. The problems seems to lie in JPATraversableResolver or maybe in PersistenceUtil within Entity Manager. The reason it worked before was that the JPATraversableResolver gets transparently added once you add the entity manager dependency.

Currently the JPATraversableResolver implementation calls
Code:
Persistence.getPersistenceUtil().isLoaded( traversableObject, traversableProperty.getName() );

within JPATraversableResolver.isReachable. This method also gets passed the element type of the property, but that information does not get used right now. The question is whether JPA requires the getter. It is also worht checking the exact contract of isLoaded.

I'm opening a Jira ticket for it - HV-320.


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Fri May 14, 2010 3:41 pm 
Newbie

Joined: Wed May 12, 2010 4:55 pm
Posts: 2
Thanks a lot!


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 4:02 am 
Newbie

Joined: Wed May 19, 2010 3:56 am
Posts: 5
Hello All,

I have the same problem with Bean Validation and hibernate 3.5.1:

javax.validation.ValidationException: Call to TraversableResolver.isReachable() threw an exception
at org.hibernate.validator.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:773)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:331)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:278)
at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:260)
....
Caused by: javax.persistence.PersistenceException: Unable to find field or method: class com.....#mailBox
at org.hibernate.ejb.util.PersistenceUtilHelper.get(PersistenceUtilHelper.java:95)
at org.hibernate.ejb.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:76)
at org.hibernate.ejb.HibernatePersistence$1.isLoadedWithReference(HibernatePersistence.java:92)
at javax.persistence.Persistence$1.isLoaded(Persistence.java:83)
at org.hibernate.validator.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:33)
...

Is there a solution or workaround for this issue?

Kind regards,

Illizi


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 4:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
The issue is already fixed in Hibernate Validator 4.1, however there is no final release yet. For now you could switch to a 4.1 SNAPSHOT.

--Hardy


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 4:21 am 
Newbie

Joined: Wed May 19, 2010 3:56 am
Posts: 5
Thank you for the fast answer.

I get also other errors after updating hibernate to 3.5.1:

org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Could not commit transaction.
....
Caused by: javax.persistence.PersistenceException: javax.validation.ConstraintViolationException: validation failed for classes [.....] during update time for groups [javax.validation.groups.Default, ]
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:1071)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:263)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
... 27 more
Caused by: javax.validation.ConstraintViolationException: validation failed for classes [......] during update time for groups [javax.validation.groups.Default, ]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:132)

Is this also fixed in 4.1?
Best regards,

Illizi


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 4:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Not sure what's happening here. Is this the full stack trace? Are you sure the the entities you are trying to persist are valid? The ConstraintViolationException seems to indicate an invalid entity.

--Hardy


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 5:33 am 
Newbie

Joined: Wed May 19, 2010 3:56 am
Posts: 5
Hello Hardy,

This is the full stack trace:

[main] 2010-05-19 11:29:06,373 WARN org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@4a479446] to process 'after' execution for test: method [public void com.illizi.domain.delivery.entity.repository.impl.DefaultPersonParametersRepositoryTest.testCreatePersonParameters()], instance [com.illizi.domain.delivery.entity.repository.impl.DefaultPersonParametersRepositoryTest@307b4703], exception [null]
org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Could not commit transaction.
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1012)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:505)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:278)
at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:171)
at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:426)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:90)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Could not commit transaction.
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1426)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1009)
... 25 more
Caused by: javax.persistence.PersistenceException: javax.validation.ConstraintViolationException: validation failed for classes [com.illizi.domain.delivery.entity.impl.DefaultPersonParameters] during update time for groups [javax.validation.groups.Default, ]
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:1071)
at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:101)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:263)
at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:86)
at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
... 27 more
Caused by: javax.validation.ConstraintViolationException: validation failed for classes [com.illizi.domain.delivery.entity.impl.DefaultPersonParameters] during update time for groups [javax.validation.groups.Default, ]
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:132)
at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:79)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:236)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:87)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:180)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
at org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:1057)
... 32 more


The exception seems to happen when trying to commit transaction.

Regards,

Illizi


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 6:36 am 
Newbie

Joined: Wed May 19, 2010 3:56 am
Posts: 5
Hello Hardy,

I've found why the exception occurs. Before commit, it seems that the bean validation is performed automatically.
The exception occurs when hibernate validator tries to validate using a cutomer validator which i've made. The validator returns false...

Before updating to hibernate 3.5.1 i did the bean validation explicitly. Is there a way to tell hibernate Not to validate the bean by calling the persist method?

Regards,

illizi


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 6:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

you can set the property javax.persistence.validation.mode to NONE. This will avoid the automatic registration of the BeanValidationListener in Hibernate Core. Other values are - AUTO, CALLBACK, NONE, DDL

--Hardy


Top
 Profile  
 
 Post subject: Re: JPATraversableResolver fails on annotated field
PostPosted: Wed May 19, 2010 7:34 am 
Newbie

Joined: Wed May 19, 2010 3:56 am
Posts: 5
Merci beaucoup! It works, except the issue with HV-320. I am looking for a workaround for it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.