请问hibernate里面的session如何保持一个字段 我是用session的.saveorUpdate(对象);但是那个表中存在一个自动增长的ID(主键),用这个也会写入那个ID,我也没对ID赋值。请问如何保存一个包含自动增长的主键的表? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 将表名.hbm.xml中的对应标识符的generator属性修改一下,例如:<id name="id", type="long" column="ID"> <meta attribute="scope-set">private</meta> <generator class="increment:/></id>再修改对应的表名.java文件private Long id;public Long getId(){ return this.id;}private void setId(Long Id){ //注意,这里是private类型 this.id=id;} 打错了,应该是<generator class="increment"/ > xml里面是<id name="provinceId" type="integer"> <column name="ProvinceID" /> <generator class="increment" /> </id>java里面也改成了private,可还是不行 报错信息有:Hibernate: insert into Audit.dbo.Province (ProvinceName, ProvinceID) values (?, ?)2007-10-22 10:46:44,390 - org.hibernate.util.JDBCExceptionReporter -0 [http-8080-2] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 544, SQLState: 230002007-10-22 10:46:44,406 - org.hibernate.util.JDBCExceptionReporter -16 [http-8080-2] ERROR org.hibernate.util.JDBCExceptionReporter - 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'Province' 中的标识列插入显式值。2007-10-22 10:46:44,437 - org.hibernate.event.def.AbstractFlushingEventListener -47 [http-8080-2] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with sessionorg.hibernate.exception.ConstraintViolationException: could not insert: [com.audit.domain.Province]Caused by: java.sql.SQLException: 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'Province' 中的标识列插入显式值。2007-10-22 10:46:44 org.apache.catalina.core.ApplicationDispatcher invoke严重: Servlet.service() for servlet jsp threw exceptionjava.lang.NullPointerException 你要做update()的话,一定要先取出这个对象了,然后修改id以外的属性,再update()就应该是没有问题的。你不能拿一个游离的对象(也就是你在程序里面new()的对象)去update()一个现成的对象,这个就算是update()了。 你定义vo对象的时候不要给它的id赋值 跪求大神啊,蛋都碎了,为什么我环境变量都配置好了,但是mySQL的驱动还是找不到 apache httpClient 散分了 某公司java笔试题 看看你能不能做上来! applet的系统时间获取问题 错误代码:001 没有这个用户 请问如何实现自动打开CMD命令提示符再输入DOS命令程序 xslt转换XML到HTML中的空格问题 调用同一个包下的几个自定义类为何无法编译? java程序分数类由一点问题,求教啊 请指教下,刚开始看java 关于jar 有关线程数的问题!!
<id name="id", type="long" column="ID">
<meta attribute="scope-set">private</meta>
<generator class="increment:/>
</id>再修改对应的表名.java文件
private Long id;public Long getId(){
return this.id;
}private void setId(Long Id){ //注意,这里是private类型
this.id=id;
}
<id name="provinceId" type="integer">
<column name="ProvinceID" />
<generator class="increment" />
</id>java里面也改成了private,可还是不行
2007-10-22 10:46:44,390 - org.hibernate.util.JDBCExceptionReporter -0 [http-8080-2] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 544, SQLState: 23000
2007-10-22 10:46:44,406 - org.hibernate.util.JDBCExceptionReporter -16 [http-8080-2] ERROR org.hibernate.util.JDBCExceptionReporter - 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'Province' 中的标识列插入显式值。
2007-10-22 10:46:44,437 - org.hibernate.event.def.AbstractFlushingEventListener -47 [http-8080-2] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.audit.domain.Province]Caused by: java.sql.SQLException: 当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'Province' 中的标识列插入显式值。2007-10-22 10:46:44 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException