2013-05-15 28 views
7

Arkadaşlarım, Hata (No doğrulayıcı türü için bulunamadı. java.util.Date)

ben ...

@NotBlank(message = "timesheet.cadastro.horainicio.obrigatorio") 
@Temporal(TemporalType.TIME) 
@Column(name = "INICIO", nullable = false) 
private Date horaInicio; 

ile sınıf var Ve testinde (Mükemmel

def "Salvar um timesheet sem hora inicio"() { 
    given:"um timesheet sem data" 
     def usuario = sessionFactory.getCurrentSession().get(Usuario.class,1L) as Usuario 
     def dias = sessionFactory.getCurrentSession().get(Dias.class,1L) as Dias 
     def timeSheet = criarTimeSheet(usuario,dias) as 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()) 
} 

ama hata var:) Ben "horaInicio" null koymak

Expected exception javax.validation.ConstraintViolationException, but got javax.validation.UnexpectedTypeException 
    at org.spockframework.lang.SpecInternals.thrownImpl(SpecInternals.java:79) 
    at br.com.infowhere.service.TimeSheetServiceIt.Salvar um timesheet sem hora inicio(TimeSheetServiceIt.groovy:80) 
Caused by: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.util.Date. 

Herkes bana yardım edebilir mi?

sayesinde

cevap

25

zamanda da @NotBlank String türü için, belgelerinde bahsedilen. Boş olan java.util.Date kavramı yok. Boş olabilir veya boş olamaz. Amaç boş değil değerdir kontrol etmek ise

Validate that the annotated string is not null or empty. The difference to NotEmpty is that trailing whitespaces are getting ignored.

, @NotNull kullanılmalıdır. Göre belgeler:

The annotated element must not be null. Accepts any type.

+0

Ben @NotNull koymak ama @NotNull (mesaj = "timesheet.cadastro.horainicio.obrigatorio") @Temporal (TemporalType.TIME) @column (name = "Inicio" :-(çalışmaz, null = false) private Tarih horaInicio; – user812612

+0

merhaba arkadaşım, özür dilerim, Şimdi işe yaramaz! Ben değişmemişti başka bir atma vardı ;-) teşekkürler !!! – user812612

-2

juste @Temporal(TemporalType.TIME) ek açıklama ;-) silmek

+0

Neden? Açıklamak. Saygılarımızla. –

+0

db'ye bağlıdır, neden mysql kaldırma @Temporal bir util.Date ile çalışacaktır. –

0
@Temporal(DATE) 
@Column(name = "creation_timestamp") 
private Date creationTimestamp; 

veya

@Temporal(TIMESTAMP) 
@Column(name = "creation_timestamp") 
private Date creationTimestamp; 

db tip 'datetime' ise

.

Basit ve işe yarıyor. Ekstra @ ek açıklama gerekmez.

İlgili konular