gpt4 book ai didi

javax.validation.ValidationException : HV000041: Call to TraversableResolver. isReachable() 抛出异常

转载 作者:搜寻专家 更新时间:2023-10-31 08:11:53 25 4
gpt4 key购买 nike

我遇到了以下错误

javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception. at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1405) at

org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1381)

at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:542) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:487) at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:451) at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:403) at org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:206) at com.demo.AdminValidator.constraintViolationsForConnMapping(AdminValidator.java:75) at com.demo.utils.tests.AdminValidatorTest.test1ConnectionIdIsRequired(AdminValidatorTest.java:121) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.NullPointerException at com.dem.model.DeploymentConfigurationMappingPK.hashCode(DeploymentConfigurationMappingPK.java:79) at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation$TraversableHolder.buildHashCode(CachingTraversableResolverForSingleValidation.java:153) at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation$TraversableHolder.(CachingTraversableResolverForSingleValidation.java:114) at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation$TraversableHolder.(CachingTraversableResolverForSingleValidation.java:96) at org.hibernate.validator.internal.engine.resolver.CachingTraversableResolverForSingleValidation.isReachable(CachingTraversableResolverForSingleValidation.java:41) at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1396

这是我的代码---------------------- Junit ----------//DeploymentConfigurationMappingPK 在构造函数中完成初始化

@Test
public void test1ConnectionIdIsRequired()
{

connectionMappingPK.setConnectionId(null);
List<String> errorMessages=null;
errorMessages=adminValidator.constraintViolationsForDeploymentConfigMapping(connectionMappingPK);

Assert.assertTrue(errorMessages.contains("ConnectionId must be specified."));
}

DeploymentConfigurationMappingPK.java

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.demo.DBConstants;

@Embeddable
public class DeploymentConfigurationMappingPK implements Serializable {

private static final long serialVersionUID = 1L;

@JoinColumn(name = DBConstants.CONNECTION_ID, nullable = false)
@Column(name = DBConstants.CONNECTION_ID, nullable = false, length = 255)
@NotNull(message="ConnectionId must be specified.")
@Size(min=1, max=255)
private String connectionId;

@Basic
@Column(name = DBConstants.APPLICATION_ID, length = 255)
@NotNull(message="ApplicationId must be specified.")
@Size(min=1, max=255)
private String applicationId;

@Basic
@Column(name = DBConstants.APPLICATION_VERSION, length = 10)
@NotNull(message="ApplicationVersion must be specified.")
@Size(min=1, max=10)
private String applicationVersion;

public String getConnectionId() {
return connectionId;
}

public void setConnectionId(String connectionId) {
this.connectionId = connectionId;
}

public String getApplicationId() {
return applicationId;
}

public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}

public String getApplicationVersion() {
return applicationVersion;
}

public void setApplicationVersion(String applicationVersion) {
this.applicationVersion = applicationVersion;
}

public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ConnectionMappingPK)) {
return false;
}
ConnectionMappingPK castOther = (ConnectionMappingPK) other;
return this.connectionId.equals(castOther.getConnectionId())
&& this.applicationId.equals(castOther.getApplicationId())
&& this.applicationVersion.equals(castOther
.getApplicationVersion());

}

public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.connectionId.hashCode();
hash = hash * prime + this.applicationVersion.hashCode();
hash = hash * prime + this.applicationId.hashCode();
return hash;

}

}

---------------------------------------- AdminValidator----- ---------------------------------------------- ----------------------------------------------

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.Demo.persistence.model.DeploymentConfigurationMappingPK ;

public class AdminValidator {

private static final Logger LOG = LoggerFactory
.getLogger(AdminValidator.class);
private ValidatorFactory factory = null;
private Validator validator = null;

public AdminValidator() {
if (factory == null) {
factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
}




public List<String> constraintViolationsForDeploymentConfigMapping(DeploymentConfigurationMappingPK connMapPK) {
if (LOG.isDebugEnabled()) {
LOG.debug("In handler #constraintViolationsDetectedForConnMapping of AdminValidator");
}
List<String> errorMessages = new ArrayList<String>();
**Set<ConstraintViolation<DeploymentConfigurationMappingPK>> constraintViolations = validator**
.validate(connMapPK);
if (constraintViolations.size() > 0)
{
Iterator<ConstraintViolation<DeploymentConfigurationMappingPK>> iterator = constraintViolations
.iterator();
while (iterator.hasNext())
{
ConstraintViolation<DeploymentConfigurationMappingPK> cv = iterator
.next();

errorMessages.add(cv.getMessage());
}

}
return errorMessages;
}
}

----------------持久性.xml ---------------------------- ----------

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="com.Demo.persistence"
transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.Demo.persistence.model.DeploymentConfigurationMappingPK</class>
<shared-cache-mode>ALL</shared-cache-mode>
<properties>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
</properties>
</persistence-unit>
</persistence>

我们在演示项目中使用了 eclipselink 和 springframework,我们没有使用 Spring MVC。

最佳答案

堆栈跟踪显示您的哈希码方法正在抛出 NPE:

Caused by: java.lang.NullPointerException at com.dem.model.DeploymentConfigurationMappingPK.hashCode(DeploymentConfigurationMappingPK.java:79) at 

您需要修复您的 hashCode 方法来处理 null。

关于javax.validation.ValidationException : HV000041: Call to TraversableResolver. isReachable() 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30333779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com