Implement your own hibernateCallback

xiaoxiao2021-03-06  43

We know, hibernateTemplate is relying on the callback function hibernateCallback to implement its feature, but in our system, this Callback may not meet our requirements. At this time, we need to realize your own hibernateCallback, this article discusss to achieve its own HibernateCallback method.

1: Disclaimer Public Interface HongsoftCallback {Object Doinhongsoft (Connection Aconn, Object Arg) THROWS HongsoftException;}

2: is defined callback function (HibernateTemplate.java) public Object load (final int id) throws DataAccessException {return execute (new HongSoftCallback () {public Object doInHongSoft (Connection aConn, Object arg) throws HongSoftException; {return aConn.load (arg. ToString (), ID);}});} This callback function is called by EXECUTE ().

3: Specific execute () method

Try {Object Result = action.doinhongsoft (conn, id); return result;} catch (hongsoftexception ex) {throw conversoftsoftException (ex);} finally {conn.close ();

4: Call the callback function return gethateTemplate (). Load (3);

转载请注明原文地址:https://www.9cbs.com/read-75075.html

New Post(0)