-->
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.  [ 1 post ] 
Author Message
 Post subject: Trouble Injecting DAO Into Hibernate Validator
PostPosted: Mon Jun 30, 2008 12:41 pm 
Newbie

Joined: Mon Jun 30, 2008 12:32 pm
Posts: 1
I am trying to insert a DAO into a custom validator to perform unique constraint validation. Code is below:

Field in my domain Object

Code:
@Required
@Length(max = 45)
@RestrictSpecialCharacters
@UniqueAliasName
public String getName() {
    return name;
}


Validator Interface
Code:
@Documented
@ValidatorClass(value = UniqueAliasNameValidator.class)
@Target(value = {ElementType.METHOD})
@Retention(value = RetentionPolicy.RUNTIME)
public @interface UniqueAliasName {

    String message() default "Alias name is already in use.";
}


Validator Class
Code:
public class UniqueAliasNameValidator implements Validator<UniqueAliasName> {

    private AliasDao aliasDao;

    public boolean isValid(Object value) {
        aliasDao = (AliasDao) Component.getInstance("aliasDao");

        boolean result = aliasDao.validateAliasNameUnique((String) value);

        return result;
    }

    public void initialize(UniqueAliasName uniqueAliasName) {}
}


DAO Method
Code:
public boolean validateAliasNameUnique(String aliasName) {
        Query query = entityManager.createNamedQuery("Alias.findByExactName");
        query.setParameter("aliasName", aliasName.toLowerCase());

        List aliasList = query.getResultList();

        return aliasList.isEmpty();
}


Originally my problem was injecting my DAO, but that seems to be working fine with the manual lookup. Everything seems to work fine until flush() is called on my EntityManager, at which point the process flow gets stuck in an infinite loop bouncing back and forth from my custom validator class to my DAO method, eventually resulting in a StackOverflowException.

I have read through several forum posts about problems identical or similar to this, but the best resolution I have found was:

"Calls to BusinessProcsessContext.flush() was causing an infinite recursion when additions or removals are not empty."

I'm not sure what this means, so that is of little help. Any help or information is appreciated.


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

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.