hibernate

chengshitao123 2016-10-16 02:20:41
在hibernate中,可以在数据库中增加和查询数据,但是无法删除和修改数据。更奇怪的是不报错,但是就是不能在数据库中看到删除了或修改了数据。

这是删除的代码:
public class DeleteProduct {

//删除指定产品信息
public static void main(String[] args) {
Session session = null; //声明Session对象
try {
//Hibernate的持久化操作
session = HibernateInitialize.getSession();//获取Session
Product product = (Product) session.get(Product.class, new Integer("1"));//装载对象
session.delete(product);//删除持久化信息
session.flush();//强制刷新提交
} catch (Exception e) {
System.out.println("对象删除失败");
e.printStackTrace();
} finally{
HibernateInitialize.closeSession();//关闭Session
}
}

}

控制台显示:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Sun Oct 16 14:20:28 GMT+08:00 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Hibernate:
select
product0_.id as id0_0_,
product0_.name as name0_0_,
product0_.price as price0_0_,
product0_.factory as factory0_0_,
product0_.remark as remark0_0_
from
tab_product product0_
where
product0_.id=?
Hibernate:
delete
from
tab_product
where
id=?

这是修改的代码:
public class UpdateProduct {

//修改指定产品信息
public static void main(String[] args) {
Session session = null; //声明Session对象
try {
//Hibernate的持久化操作
session = HibernateInitialize.getSession();//获取Session
Product product = (Product) session.load(Product.class, new Integer("10"));//装载对象
product.setName("Java Web编程词典");//修改商品名称
product.setRemark("无");//修改备注信息
session.update(product );
session.flush();
} catch (Exception e) {
System.out.println("对象修改失败");
e.printStackTrace();
} finally{
HibernateInitialize.closeSession();//关闭Session
}
}

}

控制台显示:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Sun Oct 16 14:20:56 GMT+08:00 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Hibernate:
select
product0_.id as id0_0_,
product0_.name as name0_0_,
product0_.price as price0_0_,
product0_.factory as factory0_0_,
product0_.remark as remark0_0_
from
tab_product product0_
where
product0_.id=?
Hibernate:
update
tab_product
set
name=?,
price=?,
factory=?,
remark=?
where
id=?
...全文
207 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Mithiu 2016-10-17
  • 打赏
  • 举报
回复
从你给的信息来看,好像是说Mysql5.5+的版本需要指明是否使用SSL(什么鬼我也没弄清楚),你试试在数据库连接的URL最后面加上useSSL=false试试[手动学习]

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧