Announcement Announcement Module
Collapse
No announcement yet.
StackOverflowError when using custom validator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • StackOverflowError when using custom validator

    Hi all,

    I am playing with Roo 1.1.4.RELEASE [rev f787ce7], installed petclinic sample application through clinic.roo script, point the application to local PostgreSQL DB. Can launch application and create Owner data through http://localhost:8080/petclinic.

    Then I want to include one custom validator to make sure that the email of the Owner is not duplicate. What I did:

    1. create annotation UniqueEmail:

    Code:
    @Target({ElementType.TYPE})
    @Documented
    @Constraint(validatedBy = UniqueEmailValidator.class)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface UniqueEmail {
    
        String message() default "{email-must-be-unique}";
        Class<?>[] groups() default {};
        Class<? extends Payload>[] payload() default {};
    }
    2. the implementation:
    Code:
    public class UniqueEmailValidator implements ConstraintValidator<UniqueEmail, Owner> {
    
        @Override
        public void initialize(UniqueEmail constraintAnnotation) {
        }
    
        @Override
        public boolean isValid(Owner owner, ConstraintValidatorContext context) {
    
            String email = owner.getEmail().toLowerCase();
            long count = (Long) Owner.entityManager().createQuery("select count(o) from Owner o where o.email = :email")
                    .setParameter("email", email).getSingleResult();
    
            return count == 0;
        }
    
    }
    3. Change Owner class:
    Code:
    @RooJavaBean
    @RooToString
    @RooEntity
    @UniqueEmail
    public class Owner extends AbstractPerson {
    
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
        private Set<Pet> pets = new HashSet<Pet>();
    }
    After that, when I start application through mvn tomcat:run, and try to insert one owner, I got StackOverflowError like below:

    Code:
    birthDay=2011-04-26 00:00:00.0, firstName=sdf, telephone=1234, homePage=sdf, version=0, city=sadf} 
    2011-05-20 00:41:27,335 [http-8080-1] DEBUG org.hibernate.engine.ActionQueue - changes must be flushed to space: abstract_person 
    2011-05-20 00:41:27,336 [http-8080-1] DEBUG org.springframework.beans.factory.annotation.InjectionMetadata - Processing injected method of bean 'com.springsource.petclinic.domain.AbstractPerson$1': PersistenceElement for transient javax.persistence.EntityManager com.springsource.petclinic.domain.AbstractPerson.entityManager 
    2011-05-20 00:41:27,345 [http-8080-1] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Initiating transaction rollback after commit exception 
    java.lang.StackOverflowError
    	at java.lang.StringCoding.deref(StringCoding.java:46)
    	at java.lang.StringCoding.encode(StringCoding.java:258)
    	at java.lang.String.getBytes(String.java:946)
    	at java.io.UnixFileSystem.getBooleanAttributes0(Native Method)
    	at java.io.UnixFileSystem.getBooleanAttributes(UnixFileSystem.java:228)
    	at java.io.File.exists(File.java:733)
    	at org.apache.naming.resources.FileDirContext.file(FileDirContext.java:785)
    	at org.apache.naming.resources.FileDirContext.lookup(FileDirContext.java:206)
    	at org.apache.naming.resources.ProxyDirContext.lookup(ProxyDirContext.java:299)
    	at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2807)
    	at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2668)
    	at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1124)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    	at com.springsource.petclinic.util.UniqueEmailValidator.isValid(UniqueEmailValidator.java:19)
    	at com.springsource.petclinic.util.UniqueEmailValidator.isValid(UniqueEmailValidator.java:1)
    	at org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:153)
    	at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:140)
    	at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121)
    	at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:327)
    	at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:273)
    	at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:256)
    	at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:210)
    	at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:136)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:94)
    	at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:178)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
    	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    	at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:274)
    	at com.springsource.petclinic.util.UniqueEmailValidator.isValid(UniqueEmailValidator.java:19)
    	at com.springsource.petclinic.util.UniqueEmailValidator.isValid(UniqueEmailValidator.java:1)
    	at org.hibernate.validator.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:153)
    	at org.hibernate.validator.engine.ConstraintTree.validateConstraints(ConstraintTree.java:140)
    	at org.hibernate.validator.metadata.MetaConstraint.validateConstraint(MetaConstraint.java:121)
    	at org.hibernate.validator.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:327)
    	at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForRedefinedDefaultGroup(ValidatorImpl.java:273)
    	at org.hibernate.validator.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:256)
    	at org.hibernate.validator.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:210)
    	at org.hibernate.validator.engine.ValidatorImpl.validate(ValidatorImpl.java:119)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:136)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:94)
    	at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:178)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:64)
    	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)

    Please see attached log file (application.zip) for more details.

    Can someone help me to figure out where can be the problem?

    Thank you in advance,
    george
Working...
X