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] Thu, 12 August 2010 01: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 15:57 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
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 : Twitter
Re: @Valid and collections [message #552587 is a reply to message #552559] Thu, 12 August 2010 17: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 Oct 25 03:35:42 GMT 2014

Powered by FUDForum. Page generated in 0.01530 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software