hibernate - Error with validator (No validator could be found for type: java.util.Date.) -
my friends,
i have class ...
@notblank(message = "timesheet.cadastro.horainicio.obrigatorio") @temporal(temporaltype.time) @column(name = "inicio", nullable = false) private date horainicio;
and, in test (groovy) put null "horainicio" :
def "salvar um timesheet sem hora inicio"() { given:"um timesheet sem data" def usuario = sessionfactory.getcurrentsession().get(usuario.class,1l) usuario def dias = sessionfactory.getcurrentsession().get(dias.class,1l) dias def timesheet = criartimesheet(usuario,dias) timesheet timesheet.horainicio = null when:"buscar na base" def timesheetpersistido = timesheetservice.salvar(timesheet) then:"retorna uma lista de timesheet" def erro = thrown(constraintviolationexception) "timesheet.cadastro.horainicio.obrigatorio".equals(erro.getconstraintviolations().aslist().get(0).getmessage()) }
but have error:
expected exception javax.validation.constraintviolationexception, got javax.validation.unexpectedtypeexception @ org.spockframework.lang.specinternals.thrownimpl(specinternals.java:79) @ br.com.infowhere.service.timesheetserviceit.salvar um timesheet sem hora inicio(timesheetserviceit.groovy:80) caused by: javax.validation.unexpectedtypeexception: hv000030: no validator found type: java.util.date.
anybody can me ?
thanks
as said in documentation, @notblank string type. there no concept of java.util.date being blank. can null or not null.
validate annotated string not null or empty. difference notempty trailing whitespaces getting ignored.
if goal check value not null, @notnull should used. according documentation:
the annotated element must not null. accepts type.
Comments
Post a Comment