[jboss-user] [JBoss Seam] - Object level validation

awhitford do-not-reply at jboss.com
Thu Dec 28 16:14:45 EST 2006


I am creating JPA/EJB3 entity objects, and am using Hibernate Validation annotations for some basic constraints.  And I definitely like how this validation framework is leveraged by Seam -- DRY!

But how can I best provide semantic object level validation?  For example, imagine that I have a Bond class with several properties for creating the coupons:


  | @Entity
  | public class Bond
  | {
  |     /** Primary key id */
  |     @Id
  |     @GeneratedValue
  |     private int id;
  | 
  |     @NotNull
  |     @Temporal(TemporalType.DATE)
  |     private Date issueDate;
  | 
  |     @Temporal(TemporalType.DATE)
  |     private Date datedDate;
  | 
  |     @Temporal(TemporalType.DATE)
  |     private Date firstCouponDate;
  | 
  |     @Temporal(TemporalType.DATE)
  |     private Date penultimateCouponDate;
  | 
  |     @Temporal(TemporalType.DATE)
  |     private Date maturityDate;
  | 
  |     @Column(columnDefinition = "tinyint")
  |     @Enumerated(EnumType.STRING)
  |     private CouponFrequency couponFrequency;
  | 
  |     @Column(length = 13)
  |     @Enumerated(EnumType.STRING)
  |     private AccrualMethod accrualMethod;
  | }
  | 

I need the capability to validate the bond object to ensure the following:

  | * issueDate < maturityDate
  | * issueDate < firstCouponDate
  | * issueDate < penultimateCouponDate
  | * datedDate < firstCouponDate
  | * datedDate < maturityDate
  | * datedDate < penultimateCouponDate
  | * firstCouponDate < penultimateCouponDate
  | * firstCouponDate < maturityDate
  | * penultimateCouponDate < maturityDate
  | 
And this is just the tip of the iceberg.  (Note that there are seemingly redundant checks listed because most of the columns are nullable.)

What is the best practice for enforcing object level validation?

I'm looking for a strategy whereby a validation routine could be executed to create a list of invalid values, which them Seam could report to the user -- just like other Hibernate Validation annotation restrictions like @Min, @Max, @Range, etc.

Thanks!


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996727#3996727

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996727



More information about the jboss-user mailing list