Hibernate session.save()一个问题 向大牛求救

q5620258 2013-05-11 03:29:07
我在做session.save的时候
hibernate发出2条语句
首先插入一条。然后又去修改。这是怎么回事。
Hibernate: insert into eeline.User (userCity, user_lastloginip, user_lasttime, user_name, user_nickname, user_password, user_regip, user_stauts) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update eeline.User set userCity=?, user_lastloginip=?, user_lasttime=?, user_name=?, user_nickname=?, user_password=?, user_regip=?, user_stauts=? where user_id=?

贴代码

public PK save(T entity) {
return (PK) getSession().save(entity);
}
protected Session getSession() {
Session session = null;
try {
session = sessionFactory.getCurrentSession();
} catch (HibernateException e) {
e.printStackTrace();
}
return session;
}

...全文
152 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
q5620258 2013-05-14
  • 打赏
  • 举报
回复
引用 5 楼 ch656409110 的回复:
我之前的项目也遇到过,任何新增的操作都会update一下,跟你的配置有关,,当时项目经理去掉就好了,,具体哪里真忘记了。。你看下 有不有哪些陌生的配置。。
hibernate.connection.pool_size 1 hibernate.proxool.pool_alias pool1 hibernate.format_sql false ## add comments to the generated SQL hibernate.use_sql_comments true ## set the maximum depth of the outer join fetch tree hibernate.max_fetch_depth 1 hibernate.jdbc.batch_versioned_data true hibernate.jdbc.use_streams_for_binary true hibernate.cache.region_prefix hibernate.test hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider c3p0.acquireIncrement=3 c3p0.idleConnectionTextPeriod=900 c3p0.minPoolSize=2 c3p0.maxPoolSize=50 c3p0.maxStatements=100 c3p0.numHelperThreads=10 c3p0.maxIdleTime=600 c3p0.initialPoolSize=3 没发现有可疑的配置。你帮我看看。能不能回忆出来
  • 打赏
  • 举报
回复
我之前的项目也遇到过,任何新增的操作都会update一下,跟你的配置有关,,当时项目经理去掉就好了,,具体哪里真忘记了。。你看下 有不有哪些陌生的配置。。
q5620258 2013-05-13
  • 打赏
  • 举报
回复
引用 2 楼 czw2010 的回复:
你用的hibernate4的吧,你getcurrentsession如果是交给spring管理的话,就可能有这个问题
是hibernate4,有没有见过相关原因的资料呢。google了一天都没看到具体的原因
夜之子 2013-05-12
  • 打赏
  • 举报
回复
你用的hibernate4的吧,你getcurrentsession如果是交给spring管理的话,就可能有这个问题
老伯⭐️ 2013-05-12
  • 打赏
  • 举报
回复
请楼主说明白点 插入代码不明 不知所云
xianwangkai 2013-05-12
  • 打赏
  • 举报
回复
不应该,你看一下你操作save时候有没有其它逻辑代码关于更新的。如果实在不行,你写个junit,只测试一下那个save方法,应该就知道哪里的问题!

67,513

社区成员

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

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