[
http://opensource.atlassian.com/projects/hibernate/browse/HV-438?page=com...
]
Michael Schnell commented on HV-438:
------------------------------------
I get the same error (Hibernate Validator / 4.0.2.GA) but in my case the
JPATraversableResolver seems to cause the problem:
public class JPATraversableResolver implements TraversableResolver {
// TODO Check the call to PersistenceUtil. traversableProperty.getName() is this
correct?
public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
return traversableObject == null ||
Persistence.getPersistenceUtil().isLoaded( traversableObject,
traversableProperty.getName() );
}
:
}
The problem seems to be that in the case of a (custom) class constraint
"traversableProperty.getName()" returns NULL and that leads to the same
NullPointerException. The "TODO" in the source seems to describe exactly the
problem.
Caused by: java.lang.NullPointerException
at java.lang.Class.searchFields(Class.java:2599)
at java.lang.Class.getDeclaredField(Class.java:1880)
at
org.hibernate.ejb.util.PersistenceUtilHelper$MetadataCache.findMember(PersistenceUtilHelper.java:190)
at
org.hibernate.ejb.util.PersistenceUtilHelper$MetadataCache.getMember(PersistenceUtilHelper.java:178)
at org.hibernate.ejb.util.PersistenceUtilHelper.get(PersistenceUtilHelper.java:91)
at
org.hibernate.ejb.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:83)
at
org.hibernate.ejb.HibernatePersistence$1.isLoadedWithReference(HibernatePersistence.java:93)
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)
Call to TraversableResolver.isReachable() threw an exception
------------------------------------------------------------
Key: HV-438
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HV-438
Project: Hibernate Validator
Issue Type: Bug
Components: engine
Affects Versions: 4.1.0.Final, 4.2.0.Beta1
Environment: hibernate 3.6.1.Final and hibernate validator 4.1.0.Final, GlassFish
Server Open Source Edition 3.0.1, Spring 3.0.5
Reporter: Denis Chapligin
Assignee: Hardy Ferentschik
Attachments: build.xml, hvbug.properties, validator-issue.zip
I have a problem with custom class level constraint. When I try to validate a simple
entity, like:
{code}
@Entity
@Table(name="users")
@Unique //My custom constraint
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Integer id;
}
{code}
using a spring validation helper:
{code}
User u = new User();
Errors result = new BindException(u, "User");
validator.validate(u, result);
{code}
It throws a {{NullPointerException}}:
{noformat}
Caused by: java.lang.NullPointerException
at java.lang.Class.searchFields(Class.java:2599)
at java.lang.Class.getDeclaredField(Class.java:1880)
at
org.hibernate.ejb.util.PersistenceUtilHelper$MetadataCache.findMember(PersistenceUtilHelper.java:190)
at
org.hibernate.ejb.util.PersistenceUtilHelper$MetadataCache.getMember(PersistenceUtilHelper.java:178)
at
org.hibernate.ejb.util.PersistenceUtilHelper.get(PersistenceUtilHelper.java:91)
at
org.hibernate.ejb.util.PersistenceUtilHelper.isLoadedWithReference(PersistenceUtilHelper.java:83)
at
org.hibernate.ejb.HibernatePersistence$1.isLoadedWithReference(HibernatePersistence.java:93)
at
javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Persistence.java:120)
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)
{noformat}
Some investigation revealed, that in PersistenceUtil calls the 'property'
parameter value is null and in the validator.engine functions 'name' var in value
of the first and single entry of propertyPath.nodeList is null too.
Most interested thing is that when i try validation code, shown above, in JUnit
environment, it works well.
I've attached a simple webapp, that reproduces the issue. It is too big, to be
uploaded here, so i put it to the dropbox:
http://dl.dropbox.com/u/17691684/hvbug.tar.gz
Initial report was on hibernate forums:
https://forum.hibernate.org/viewtopic.php?f=9&t=1009612&start=0
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira