Hi. We have a quite common requirement of previewing changes on an object before storing the results in the DB. This is for a CMS.
The object is send from the frontend incomplete, i.e., in non-cascaded associations only the ID is sent, but in order to preview we need the full object. The preview involves marshalling the object into XML, which is then transformed to HTML using XSLT.
Session.refresh() only works with objects already in the session, so we thought about using a read only transaction, invoking Session.saveOrUpdate() and then Session.refresh(), so we have a "full" object to marshal to XML.
Unfortunately, Oracle JDBC driver doesn't support read only connections, so we are rolling back the transaction after that. This seems as it could work, but rolling back for previewing doesn't feel very elegant.
As this is a common use case, are there any other approaches that work for you?
Because we need the ability of previewing both new and already existing objects, we thought about resetting the ID of existing ones and storing a new object (replicating?) in the DB, but this has the problem of relationships with cascade update operations, which would be changed. I don't know if Session.replicate() would help with this, but I don't think so. Maybe Beanlib's HibernateBeanReplicator could help, but this seems as a more complex solution and it would pollute our DB.
Thanks in advance.
|