Hibernate 中用对象 Session。delete()方法删除 action中用反射获取对象为什么不好使?代码如下
Actiontry{Methodm=cls.getDeclaredMethod("setId",int.class);m.invoke(objtable,nid);}ca...
Action
try
{
Method m= cls.getDeclaredMethod("setId", int.class);
m.invoke(objtable,nid);
}
catch(Exception e){}
String s=d.delete(objtable);
out.println("deleted "+nid);
Bean
public static String delete(Object obj)
{
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf= cfg.buildSessionFactory();
Session session=sf.openSession();
Transaction tx = session.beginTransaction();
session.delete(obj);
tx.commit();
session.close();
return "";
} 展开
try
{
Method m= cls.getDeclaredMethod("setId", int.class);
m.invoke(objtable,nid);
}
catch(Exception e){}
String s=d.delete(objtable);
out.println("deleted "+nid);
Bean
public static String delete(Object obj)
{
Configuration cfg = new Configuration();
cfg.configure();
SessionFactory sf= cfg.buildSessionFactory();
Session session=sf.openSession();
Transaction tx = session.beginTransaction();
session.delete(obj);
tx.commit();
session.close();
return "";
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询