public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on PersistenceManager interface coming in... if (method.getName().equals("equals")) { // Only consider equal when proxies are identical. return (proxy == args[0] ? Boolean.TRUE : Boolean.FALSE); } else if (method.getName().equals("hashCode")) { // Use hashCode of PersistenceManager proxy. return new Integer(System.identityHashCode(proxy)); } else if (method.getName().equals("close")) { // Handle close method: only close if not within a transaction. if (this.persistenceManagerFactory != null) { PersistenceManagerFactoryUtils.doReleasePersistenceManager( this.target, this.persistenceManagerFactory); } return null; } // Invoke method on target PersistenceManager. try { return method.invoke(this.target, args); } catch (InvocationTargetException ex) { throw ex.getTargetException(); } }