Hibernate session.save()一个问题 向大牛求救
我在做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;
}
Hibernate Java --------------------编程问答-------------------- 请楼主说明白点
插入代码不明 不知所云 --------------------编程问答-------------------- 你用的hibernate4的吧,你getcurrentsession如果是交给spring管理的话,就可能有这个问题 --------------------编程问答-------------------- 不应该,你看一下你操作save时候有没有其它逻辑代码关于更新的。如果实在不行,你写个junit,只测试一下那个save方法,应该就知道哪里的问题! --------------------编程问答--------------------
是hibernate4,有没有见过相关原因的资料呢。google了一天都没看到具体的原因 --------------------编程问答-------------------- 我之前的项目也遇到过,任何新增的操作都会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
没发现有可疑的配置。你帮我看看。能不能回忆出来
补充:Java , Java EE