I've recently begun a project to convert an EJB application (session and entity beans) to Spring/Hibernate and have an architectural question for those that have blazed ahead.
I've read in a few places that using accessor methods is recommended over direct field access for the mappings. However, this makes my public accessors less elegant than I had hoped. When a client calls a setter, I want to apply validation checks (not null, cannot overwrite existing non-null value, etc), but I don't want those to interfere with Hibernate loading an object from the database.
One solution I see is to have two sets of accessors: one set for clients and another stripped-down set for Hibernate. However, it seems no different at that point from using direct field access.
What have others found with both methods, and are there any particular gotchas when using direct field access?
Thanks!
|