You're referring to the object id in File#hashCode()
and are using generation type IDENTITY
which will obtain id values from an identity column in the database, i.e. an access to the DB is required to obtain ids. Apparently your entities are instrumented in a way which causes a flush to happen for that purpose just when reading the id property.
You could try and change your hashCode()
implementation in a way that it isn't based on the primary key but on the "business identity" of the entity, e.g. the file name or path.
That said, I think Hibernate Validator shouldn't invoke the hashCode()
method of entities in this situation, so I've filed HV-848 to get this changed.