You shouldn't be doing that.
You either want to trim your data coming in that you never save the trailing/leading whitepsace.
Past that, if you need to deal with this data in the database you want to use an approiprate lucene analyzer that will will handle this for you. Honestly I think any of the built in analzyers should allow you to search for "xyz" and find "xyz " except for the NotAnalyzed which is meant to store tokens EXACTLY as they are, this is mainly only useful for primary keys / guids.