You have a couple options depending on what behavior you want.
A custom setter, which will trim the value every time you set it
class Book { String name void setName(String name) { this.name = name?.trim() } }
A custom getter, which will give you a trimmed value but not store it in the database
class Book { String name String getName() { this.@name?.trim() } }
A hibernate event, like
beforeSave()
as you mentioned, which will only trim it before the object is persisted.