kgignatyev wrote:
I suggest adding Tapestry (I think it will blow you away too) to the mix and letting Servlet filter to take care of Hibernate session management.
I'll look into it.
Now I have changed it so that I have some custom annotations, so in my business classes, I can note things like "instances of this class should be unique" and then I can note properties as being parts of the business key. Then my Servlet introspects those objects and does a query to make sure that the object is unique before it is saved. Somehow once I get all these tools (Hibernate, introspection, annotations) working together I'll finally be exactly where I want, which is I write zero SQL, few servlets, and most of my time is writing business objects the way I want them. This will be an amazing enhancement, because before I would spend most of my time dealing with servlets.
Now the remaining thing I have to figure out is this:
If there is a unique constraint on my class, what I do is I make up a "test instance" and do a query-by-example to see if there is a match. However, before I do that I also make up a PropertySelector so that only business keys (which I got from reading annotations) are compared. That's all great, except that one of the business keys is not a property, but rather an association. In my particular case, I'm creating a system where users can manage a calendar. Of course they put things into Categories, and of course Category should be unique for every user. QBE doesn't work because User isn't a property of Category; User is an entity and it's connected by a many-to-one association.
So that's the next thing to figure out: how to use the annotations to define the biz key when the biz key uses associations AND properties. I think I'll have that figured out tonight.