I'm executing a method at startup time with @PostConstruct
annotation. This method has to check a value stored in a table in DB. If it doesn't exist, then it has to insert it. The checking of the value in DB is done correctly, however if I had to persist it, it won't write it to DB. It doesn't throw any exception and persist()
is executed (apparently) without problems, only the value is not inserted in DB.
Moreover, once everything is up, if I manually call that method (from a Controller, for example), it will insert the value correctly.
@PostConstruct
public void insertIfNecessary()
{
Request r = Request.findRequestForUser(this.me);
if ( r == null )
{
r = new Request();
r.setOwner(this.me);
r.persist();
}
}
Do you know what may be wrong?
Best regards, Miguel