Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @Valid and collections(Only first invalid member of collection attribute has ConstraintViolation)
@Valid and collections [message #552381] Wed, 11 August 2010 21:25 Go to next message
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!
Re: @Valid and collections [message #552559 is a reply to message #552381] Thu, 12 August 2010 11:57 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1834
Registered: July 2009
Senior Member
Note that EclipseLink does not throw constraint violations, you are using some other library for this validation, is it not an issue with this other library?


James : Wiki : Book : Blog
Re: @Valid and collections [message #552587 is a reply to message #552559] Thu, 12 August 2010 13:39 Go to previous message
Jay McGavren
Messages: 4
Registered: July 2010
Location: Phoenix, AZ
Junior Member
Sorry, I thought EclipseLink was handling the bean validation as well. Thanks anyway!
Previous Topic:How to use MOXy provider with Glassfish server
Next Topic:JoinFetch does not work with ORDER BY in query
Goto Forum:
  


Current Time: Sat May 18 13:00:09 EDT 2013

Powered by FUDForum. Page generated in 0.02119 seconds