我有一个服务方法尝试添加一个对象store()
冬眠的方法。 get 方法适用于此 DAO 和服务类,而添加方法则不起作用。在控制台中没有错误。
UrlWhiteListDaoImpl urlDao;
MapperFacade mapper;
@Autowired
public UrlWhiteListingServiceImpl(UrlWhiteListDao urlWhiteListDao, MapperFacade mapper, UrlWhiteListDaoImpl urlDao) {
this.urlDao = urlDao;
this.urlWhiteListDao = urlWhiteListDao;
this.mapper = mapper;
}
@Override
public UrlWhiteListDto addUrlWhiteListItem(UrlWhiteListDto urlWhiteListDto) throws Exception {
String domainUrlToBeAdded = parseUrl(urlWhiteListDto.getDomain());
if (isDomainExistbyName(domainUrlToBeAdded)) {
throw new Exception("Already existed domain is tried to be added");
}
UrlWhitelist urlModel = mapper.map(urlWhiteListDto,UrlWhitelist.class);
urlDao.store(urlModel);
return urlWhiteListDto;
}
我的模型类是:
@Entity
@Table(name = UrlWhitelist.TABLE_NAME)
public class UrlWhitelist implements EntityBean {
public static final String TABLE_NAME = "URL_WHITE_LIST";
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", nullable = false)
private Long id;
@NotBlank
@Column(name = "DOMAIN", nullable = false)
private String domain;
@NotBlank
@Column(name = "DISABLE", nullable = false)
private boolean disabled;
// getters & setters omitted
}
而DAO的实现类是:
public class UrlWhiteListDaoImpl extends EntityDaoImpl<UrlWhitelist, Long> implements UrlWhiteListDao {
protected UrlWhiteListDaoImpl() {
super(UrlWhitelist.class);
}
@Override
public List<UrlWhitelist> getByDomainName(String name) {
DetachedCriteria criteria = DetachedCriteria.forClass(UrlWhitelist.class);
criteria.add(Restrictions.eq("domain", name));
return getAllByCriteria(criteria);
}
}
在控制台中没有错误,但在服务器日志中显示:
严重:路径 [] 上下文中 servlet [服务] 的 Servlet.service() 抛出异常 [请求处理失败;嵌套异常是 javax.validation.UnexpectedTypeException: HV000030: 找不到约束“org.hibernate.validator.constraints.NotBlank”验证类型“java.lang.Boolean”的验证器。检查配置“已禁用”]及其根本原因
javax.validation.UnexpectedTypeException:HV000030:找不到约束“org.hibernate.validator.constraints.NotBlank”验证类型“java.lang.Boolean”的验证器。检查“禁用”配置
我认为 to 和模型类之间的映射有问题,但是,为什么 get 方法有效并且仅store()
不管用?解决办法是什么 ?