0
Class MyModel {

    public interface ServerGroup {}
    @NotNull
    private String name;

    @Size(min = 1, groups=ServerGroup.class)
    //@NotEmpty(groups=ServerGroup.class) // Tried this as well but not working!
    @OneToMany
    //@OneToMany(fetch=FetchType.EAGER) It works! Don't really want to do eager fetch
    private List<Person> persons = new ArrayList<Person>();


  //getters and setters here
  .....
}


Class Mytest {

@Test
public void testMyModel
MyModel myModel = new MyModel();
myModel.setName("This is testing");
persist(myModel); //persisting to database

//Now loading back again from database
MyModel myModel = MyModel.Service.findMyModelByName("This is testing");
Set<ConstraintViolation<MyModel>> violations = validator.validate(myModel,ServerGroup.class);
Assert.assertEquals(1, violations.size()); //It fails here saying no violation
}

ご覧のとおり、人が空のデータベースからmymodelを作成してロードしたので、ServerGroup'group'に対して検証を実行してみてください。ただし、違反はありません。これを積極的なロードに変更すると、機能しますか?何か提案をお願いします。

4

0 に答える 0