Re: BeanEditForm onValidate()

2018-01-16 Thread Chris Poulsen
You could try setting a break point in the database update code and some in
the event handlers and the examine the call stack to see where the call
originates from and in which order things happen

-- 
Chris

On Tue, Jan 16, 2018 at 10:51 AM, JumpStart <
geoff.callender.jumpst...@gmail.com> wrote:

> If Hibernate is creating/updating the database definition then you could
> be right. I’m not sure because I use this kind of thing for alternate key:
>
> @Entity
> @Table(name = "Users", uniqueConstraints = { @UniqueConstraint(columnNames
> = { “username" }) })
> public class User ...
>
>
> > On 16 Jan 2018, at 5:42 pm, Christopher Dodunski  christopher.net.nz> wrote:
> >
> > Hi Geoff,
> >
> > Sorry, I'll try that when back at my PC tomorrow.
> >
> > I could be mistaken, but does the 'column' annotation below not set the
> > USER_NAME column in the database as unique?  I assumed this is the reason
> > for the ConstraintViolationException, i.e. the unique field.
> >
> > Irrespective, I'll do as you suggested in onActivate() and see what
> > results.  :-)
> >
> >//@NaturalId
> >@Column(name="USER_NAME", nullable=false, unique=true, length=50)
> >@Validate("required")
> >@NotNull
> >@Size(min = 4, max = 50)
> >@Alphanumeric
> >private String userName;
> >
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > For additional commands, e-mail: users-h...@tapestry.apache.org
> >
>
>


Re: BeanEditForm onValidate()

2018-01-16 Thread JumpStart
If Hibernate is creating/updating the database definition then you could be 
right. I’m not sure because I use this kind of thing for alternate key:

@Entity
@Table(name = "Users", uniqueConstraints = { @UniqueConstraint(columnNames = { 
“username" }) })
public class User ...


> On 16 Jan 2018, at 5:42 pm, Christopher Dodunski 
>  wrote:
> 
> Hi Geoff,
> 
> Sorry, I'll try that when back at my PC tomorrow.
> 
> I could be mistaken, but does the 'column' annotation below not set the
> USER_NAME column in the database as unique?  I assumed this is the reason
> for the ConstraintViolationException, i.e. the unique field.
> 
> Irrespective, I'll do as you suggested in onActivate() and see what
> results.  :-)
> 
>//@NaturalId
>@Column(name="USER_NAME", nullable=false, unique=true, length=50)
>@Validate("required")
>@NotNull
>@Size(min = 4, max = 50)
>@Alphanumeric
>private String userName;
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
> 



Re: BeanEditForm onValidate()

2018-01-16 Thread Christopher Dodunski
Hi Geoff,

Sorry, I'll try that when back at my PC tomorrow.

I could be mistaken, but does the 'column' annotation below not set the
USER_NAME column in the database as unique?  I assumed this is the reason
for the ConstraintViolationException, i.e. the unique field.

Irrespective, I'll do as you suggested in onActivate() and see what
results.  :-)

//@NaturalId
@Column(name="USER_NAME", nullable=false, unique=true, length=50)
@Validate("required")
@NotNull
@Size(min = 4, max = 50)
@Alphanumeric
private String userName;


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: BeanEditForm onValidate()

2018-01-16 Thread JumpStart
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 
>  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
>