scesbron
Dec 21st, 2004, 05:25 AM
Hi,
I have some troubles using transparent persistence tool with the DAO pattern. In my case I am using hibernate
1/ With automatic dirty checking, hibernate flushes modifications on my domain object each time I do a query. How can I handle this if I do some queries to validate my object ?
2 / Unique constraint
This is my main problem and the most generic one. Transparent persistence tool like hibernate and jdo give me automatic dirty checking. So, as I saw in juergen's chapter on dao, I do not need to call explicit update methods. So how can I verify my unique constraint ?
I saw on different threads that I can use my db constraints' names and rely on the db to verify my constraints. I have a problem with that : how can I achieve that when I persist a class hierarchy in one table ? I can have a unique constraint on one part of the hierarchy (one child class) but not on the whole hierarchy. Thus I cannot put my constraint in my db.
Here are my thought on how I can handle the problem
a) I put my check in an update method inside my dao. With this solution I have two possibilities
Developpers have to call this method but I cannot ensure they do
I add some home made code in my app to partially disable automatic dirty checkin. I throw an exception if hibernate try to update an object without previous call to my method : this seems a little bit tricky for dependent objects
b)I use the validator to ensure my unique constraint : I do not know if this is possible. To do that my validator must have access to the hibernate session.
With both solutions I fall into my first problem. to test uniqueness on update I have to count the number of elements in the database but if I do so hibernate flush my session and update my object in the db before the count.
Another problem with transparent persistence framework. I would like to have some 'onSave' and 'onUpdate' events thrown each time a domain object is created or modified. I would like to handle this in my daos but how can I achieve this without update method in my daos.
In conclusion I would like to know why I seem to be the only one disturb with automatic dirty checking.
thanx in advance
Seb
I have some troubles using transparent persistence tool with the DAO pattern. In my case I am using hibernate
1/ With automatic dirty checking, hibernate flushes modifications on my domain object each time I do a query. How can I handle this if I do some queries to validate my object ?
2 / Unique constraint
This is my main problem and the most generic one. Transparent persistence tool like hibernate and jdo give me automatic dirty checking. So, as I saw in juergen's chapter on dao, I do not need to call explicit update methods. So how can I verify my unique constraint ?
I saw on different threads that I can use my db constraints' names and rely on the db to verify my constraints. I have a problem with that : how can I achieve that when I persist a class hierarchy in one table ? I can have a unique constraint on one part of the hierarchy (one child class) but not on the whole hierarchy. Thus I cannot put my constraint in my db.
Here are my thought on how I can handle the problem
a) I put my check in an update method inside my dao. With this solution I have two possibilities
Developpers have to call this method but I cannot ensure they do
I add some home made code in my app to partially disable automatic dirty checkin. I throw an exception if hibernate try to update an object without previous call to my method : this seems a little bit tricky for dependent objects
b)I use the validator to ensure my unique constraint : I do not know if this is possible. To do that my validator must have access to the hibernate session.
With both solutions I fall into my first problem. to test uniqueness on update I have to count the number of elements in the database but if I do so hibernate flush my session and update my object in the db before the count.
Another problem with transparent persistence framework. I would like to have some 'onSave' and 'onUpdate' events thrown each time a domain object is created or modified. I would like to handle this in my daos but how can I achieve this without update method in my daos.
In conclusion I would like to know why I seem to be the only one disturb with automatic dirty checking.
thanx in advance
Seb