package persistence;


import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


public class NotFullValidator implements ConstraintValidator<NotFull, Department> {
	
	@Inject private EntityManager em; //we will not use it, but if we neeed it for a very complex validation, this would be a good approach

	public void initialize(NotFull constraintAnnotation) {
    }

    public boolean isValid(Department department, ConstraintValidatorContext constraintContext) {
    	System.err.println("============= EM AT VALIDATOR: "+em);
    	if (department == null) return true;
        return department.getEmployees().size() <= department.getSize();
        
    }

}
@@ -15,17 +15,16 @@
 tence;%0A%0A
-%0A
 import j
@@ -212,16 +212,23 @@
 lidator 
+%0A%09%09%09%09%09%09
 implemen
@@ -280,63 +280,189 @@
 %0A%09%0A%09
-@Inject private EntityManager em; //we will not use it,
+// If we need to access the database for validating an object?%0A%09// Solution: Use java CDI and request an EntityManager to be injected.%0A%09// We will not use it in this validator, %0A%09//
  but
@@ -471,17 +471,16 @@
 f we nee
-e
 d it for
@@ -507,16 +507,21 @@
 dation, 
+%0A%09// 
 this wou
@@ -541,16 +541,52 @@
 approach
+%0A%09@Inject private EntityManager em; 
 %0A%0A%09publi
@@ -669,16 +669,23 @@
 isValid(
+%0A    %09%09
 Departme
@@ -699,16 +699,23 @@
 rtment, 
+%0A    %09%09
 Constrai
@@ -750,24 +750,30 @@
 tContext) %7B%0A
+    %09%0A
     %09System.

Add some comments and code format