【发布时间】:2011-07-13 10:28:56
【问题描述】:
我正在使用 Hibernate 访问我的数据库。我想删除一组关于标准功能的字段。我的数据库是 PostgreSQL,我的 Java 代码是:
public void deleteAttr(String parameter){
Configuration cfg = new Configuration();
cfg.configure(resource.getString("hibernate_config_file"));
SessionFactory sessionFactory = cfg.buildSessionFactory();
session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
tx.begin();
String sql = "delete from attribute where timestamp > to_date('"+parameter+"','YYYY-MM-DD')"
session.createSQLQuery(sql);
tx.commit();
}
该方法运行,但它不会从数据库中删除数据。我还检查了 PgAdmin 中的 sql 语句,它有效,但在代码中无效。为什么?有人帮我吗?
提前致谢!
【问题讨论】:
标签: database hibernate postgresql