我实现了级联删除的一对多代码映射。我有与子实体关联的文件。我想在子级联删除时自动删除文件。 如何实施?
答案 0 :(得分:1)
我发现NHibernate支持配置级别的监听器。它并不完美,但总比没有好。简化示例:
private Hashtable<Object,Object> htObjClass;
private String evalReflectionFunction(String varMethodName, String varClassName,Table objTable)
{
String strReturnValue = "";
try
{
LinkedHashMap<String, String> hashtable = new LinkedHashMap<String, String>();
.
.
// NOTE : below given jar path is same for all threads
File seleniumJarFile = new File(jarpath);
URLClassLoader myClassLoader = new URLClassLoader(new URL[]{seleniumJarFile.toURI().toURL()},Thread.currentThread().getContextClassLoader());
if(!this.htObjClass.containsKey(varClassName))
{
Class<?> dynamicClass = (Class<?>) myClassLoader.loadClass("packageName."+varClassName);
Constructor<?> cons = dynamicClass.getConstructor(RunEnvironment.class);
htObjClass.put(varClassName,cons.newInstance(this.objRunEnvClass));
}
Object obj2 = this.htObjClass.get(varClassName);
Method method = obj2.getClass().getDeclaredMethod(varMethodName, LinkedHashMap.class);
if(method != null)
Object retVal = method.invoke(obj2, hashtable);
else
strReturnValue = "Error-text";
}
catch(Exception ex)
{
......
}
return strReturnValue;
}