当你阅读这个帖子的时候,我就知道你一定又遇到问题了,别着急....
这里我叨逼叨两个问题: 1.save()操作无效 2.update()操作无效
你会问“这个两个问题难道不是同一个原因造成的么?”
我遇到的情况不是,下面上菜
1.save()操作无效 的问题
问题表象: 控制台不报异常,不输出 insert 语句
打开你的实体类: 如果你的生成策略是@GeneratedValue(strategy= GenerationType.AUTO)
请更换为 @GeneratedValue(strategy= GenerationType.IDENTITY)
如下:
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name="id")
private Long id;
能不能解决你的问题我不确定,解决了我的问题
2.update()操作无效
打开你的Dao基类,如果你使用的是通过SessionFactory获取Session进行操作
请将
this.sessionFactory.OpenSession();
改为
this.sessionFactory.getCurrentSession();
这里你可能会问了,SpringBoot注入SessionFactory怎么玩?
看下面的代码:
@PersistenceContext
protected EntityManager entityManager;
protected Session getSession() {
return entityManager.unwrap(Session.class);
}
QQ群放这里:578060039 我发了,你随意
打完收工