samedi 28 février 2015

Spring Hibernate Bean Validation @valid

I know it is not new question in this forum but I am very confused what should i do.


Problem: I am developing one application with spring mvc + hibernate. For server side validation I am using @valid annotation in controller and @null and @notNull annotation in my bean.


e.g



public class User implements Serializable {

private static final long serialVersionUID = 2158419746939747203L;

@Id
@Column(name="USER_ID")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long userId;

@Column(name="USERNAME", unique = true)
@NotEmpty @NotNull @Size(min=6, max=20)
private String username;

@Column(name="PASSWORD")
@NotEmpty @NotNull @Size(min=6, max=20)
private String password;


This validation is happening fine and data is also saving in DB.


But I want to validate unique constraint,referential integrity and other constraint using annotation without any validator class.


Is it possible? if no, then what is best and easiest way to to do it(less coding)? I will appreciate if framework will do it for me.


Aucun commentaire:

Enregistrer un commentaire