Did you miss my suggestion? 

        Try putting it in onActivate and pass it 'Abel'.

I’m hoping it will have the same problem, because, as you know, it makes no 
sense that a transaction has taken place before onValidate().

Longer term, however, you should scrap the validation because it can be subject 
to a race condition. Instead, in the database make username UNIQUE, and on 
insert or update it will fail if username is not unique. It’s easy enough to 
interpret the error to determine to was due to “alternate key not unique”.

> On 15 Jan 2018, at 7:21 pm, Christopher Dodunski 
> <chrisfromtapes...@christopher.net.nz> wrote:
> 
> To summarise...
> 
> the exceptions:
> 
>    org.hibernate.exception.ConstraintViolationException
> 
>    could not execute statement
> 
>    SQL
>        n/a
>    SQLState
>        23000
>    errorCode
>        1062
> 
> and:
> 
>    java.sql.SQLIntegrityConstraintViolationException
> 
>    Duplicate entry 'Abel' for key 'UK_h029unq4qgmbvesub83df4vok'
> 
>    SQLState
>        23000
>    errorCode
>        1062
> 
> is thrown when the below line is reached in onValidate():
> 
>    User userVerif =
> crudServiceDAO.findUniqueWithNamedQuery(User.BY_USERNAME,
> QueryParameters.with("userName", user.getUserName()).parameters());
> 
> yet this is only calling the below 'HQL select' NamedQuery:
> 
>    @NamedQuery(name = User.BY_USERNAME, query = "Select u from User u
> where u.userName = :userName"),
> 
> which raises the question:
> 
>    Who or what is automatically attempting to illegally persist a user
> with duplicate userName?  BeanEditForm?  Hibernate?  Ghosts?
> 
> Quoting from http://tapestry.apache.org/beaneditform-guide.html:
> 
>    Automatic Object Creation
> 
>    If the object does not exist, it will be created as needed.
> 
> Does altering the userName field (a unique field) invoke this "automatic
> object creation"?  I don't imagine this is the case, else why would
> BeanEditForm bother firing a 'validate' event?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 

Reply via email to