Validation Extension

This is a simple extension to Morphia to process JSR 303 Validation Annotations.


Add this at the start of your application (or wherever you create your morphia instances).

new ValidationExtension(morphia);



Here is a simple example using (as an example) Hibernate validation:

import org.hibernate.validator.constraints.Email;

public class Userlike {
	@Id ObjectId id;
	@Email String email;


This is a lightweight wrapper around the JSR 303 API. It installs a simple global entity interceptor which listens to all life cycle methods needed for validation. You can use any implementation of JSR 303 by just adding it to the classpath.

You can look at the code here.



If you use Maven to manage your project, you can reference Morphia as a dependency: