I wrote a validator to check for duplicate usernames. I thought validation was only called on a store or update operation.
Code:
public boolean isValid(Object value)
{
String username = (String)value;
UserAccountManager manager =
(UserAccountManager)Component.getInstance("userAccountManager");
//no change to username
if( username.equals(manager.getPreviousUsername()) )
{
return true;
}
UserAccount account = manager.findUserAccount(username);
if(account == null)
{
return true;
}
return false;
}
I wouldn't think that this would cause a store or update operation.
Code:
public UserAccount findUserAccount( String searchName )
{
UserAccount account;
try{
account = (UserAccount)em.createQuery
("select a from UserAccount a where a.username = :name")
.setParameter("name", searchName)
.getSingleResult();
} catch (NoResultException ex) {
account = null;
}
return account;
}
But the Exception stack shows a continual looping. Looks like a call to auto flush might be the cause. Am I doing something to cause this? Shouldn't I be able to do a read operation within a validator. I think I can do a workaround but I would like to understand why this is happening.
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:341)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:307)
at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:134)
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
at org.domain.BeReadyCounty.action.UserAccountManagerBean.findUserAccount(UserAccountManagerBean.java:104)
at org.domain.BeReadyCounty.model.UsernameValidator.isValid(UsernameValidator.java:33)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:341)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:307)
at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:134)
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
at org.domain.BeReadyCounty.action.UserAccountManagerBean.findUserAccount(UserAccountManagerBean.java:104)
at org.domain.BeReadyCounty.model.UsernameValidator.isValid(UsernameValidator.java:33)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:341)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:307)
at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:134)
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
at org.domain.BeReadyCounty.action.UserAccountManagerBean.findUserAccount(UserAccountManagerBean.java:104)
at org.domain.BeReadyCounty.model.UsernameValidator.isValid(UsernameValidator.java:33)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:341)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:307)
at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:134)
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
at org.domain.BeReadyCounty.action.UserAccountManagerBean.findUserAccount(UserAccountManagerBean.java:104)
at org.domain.BeReadyCounty.model.UsernameValidator.isValid(UsernameValidator.java:33)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:341)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:307)
at org.hibernate.validator.event.ValidateEventListener.validate(ValidateEventListener.java:134)
at org.hibernate.validator.event.ValidateEventListener.onPreUpdate(ValidateEventListener.java:172)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:217)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:65)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:80)
at org.domain.BeReadyCounty.action.UserAccountManagerBean.findUserAccount(UserAccountManagerBean.java:104)
at org.domain.BeReadyCounty.model.UsernameValidator.isValid(UsernameValidator.java:33)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:341)
at org.hibernate.validator.ClassValidator.getInvalidValues(ClassValidator.java:307)
Thanks for any knowledge.