-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: @Size/@Length built in constraint
PostPosted: Thu Apr 17, 2008 1:45 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
It would be nice to have a unique constraint for size instead of one for each type.
That is, instead of writting a code as this one:
Code:
public class Invoice {

  @Max(99999)
  private Integer code;

  @Length(max=40)
  private String concept;

  @Max(999999999999l)
  private BigDecimal amount;

  @Size(max=60)
  private Collection<InvoiceDetail> details;
  ...
}

It's better to write the Invoice class in this way:
Code:
public class Invoice {

  @Size(max=5)
  private Integer code;

  @Size(max=40)
  private String concept;

  @Size(max=12)
  private BigDecimal amount;

  @Size(max=60)
  private Collection<InvoiceDetail> details;
  ...
}


@Size or @Length or whatever else, but not a different annotation for each type.
In this way the class is easier to write and to read, is it ?

This constraint can be implemented using 'Polymorphic constraints':
http://forum.hibernate.org/viewtopic.php?t=985711

What do you think about this ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 23, 2008 8:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This can be done.

Note that
@Size(5) int code;
is (more or less) equivalent to
@Length(max=5) int code;
but is different than
@Max(5) int code;

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 1:49 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
emmanuel wrote:
This can be done.

Great!

Quote:
Note that
@Size(5) int code;
is (more or less) equivalent to
@Length(max=5) int code;
but is different than
@Max(5) int code;

I know. Look at the code example above.

Cheers


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.