@Valid and collections [message #552381] |
Thu, 12 August 2010 01:25 |
Jay McGavren Messages: 4 Registered: July 2010 Location: Phoenix, AZ |
Junior Member |
|
|
I have a List<T> attribute that only gives one ConstraintViolation, even when more than one of its members should fail validation...
//City.java
@Entity
@Table(name="cities")
@GroupSequence({Basic.class, PointOfInterest.class, Extended.class})
public class PointOfInterest implements Serializable {
@XmlElement(name = "Name", required=true)
@OneToMany(mappedBy="point", fetch=FetchType.EAGER, cascade={CascadeType.ALL})
@Size(min=1, groups=Basic.class)
@Valid
private List<Name> names = new ArrayList<Name>();
//...
//Name.java
@Entity
@Table(name="city_nm")
@GroupSequence({Basic.class, Name.class, Extended.class})
public class Name implements Serializable {
@XmlAttribute
@NotNull(groups=Basic.class)
@Size(min=2, max=250, groups=Basic.class)
@Column(name="city_nm", nullable=false, length=250)
private String name;
//...
//CityTests.java
@Test
public void multipleInvalidNames() throws Exception {
City city = factory.makeCity();
Name name1 = factory.makeName();
name1.setName("a"); //Below @Size min!
city.addName(name1);
Name name2 = factory.makeName();
name2.setName("b"); //Also too short!
city.addName(name2);
Set<ConstraintViolation<?>> errors = tryPersist(city).getConstraintViolations();
//...
errors.toString() gives me:
[ConstraintViolationImpl{interpolatedMessage='size must be between 2 and 250', propertyPath=name, rootBeanClass=class com.my.city.domain.Name, messageTemplate='{javax.validation.constraints.Size.message} '}]
...so that first Name seems to have been flagged as too short, but I'd have expected a second ConstraintViolation for the second name. Should I have gotten one?
Many thanks for any advice/leads anyone can offer!
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02972 seconds