【报错】 ids for this class must be manually assigned before calling save()
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): po.UserEntity
错误提示是说,id的生成错误,在保存之前,需先生成。
方法一:
user.setId("09");
强行声明。。。。。。
方法二:
xml配置:主键处添加
https://blog.csdn.net/mjlfto/article/details/81951255?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase
分析及解决:
你要操作的数据表中的id(即主键)的类型设置成了“自动增长类型”,而在你的
hibernate.cfg.xml中,id的生成方式是assigned,即
<id name="id" type="integer">
<column name="id" />
<generator class="assigned" />
</id>
这种搭配是矛盾的!
主键的assigned生成方式由程序自动生成表的主键,即在你的测试程序中要调用setId()方法,且必
须在调用save()前调用(或者说在调用save()前必须指定id,其实就是说,主键值不能为空!)。
把主键的生成方式改为native,它的特征是能够根据底层数据库自动选择主键生成方式。
原文链接:https://blog.csdn.net/yoyofish0001/article/details/84446110
修改后报错
<id name="id" column="id" ><generator class="native" /></id>
ERROR: Field 'id' doesn't have a default value
产生的原因:主要来自于mysql数据库的自增主键,id不能是默认的值,
也就是说我们没有进行自增主键的设置。
只需要连接至自己的mysql数据库将主键PRIMARY KEY,设置为自增值即可。
alter table 表名 change id id int AUTO_INCREMENT
添加此语句在JDBC 解决问题
【报错】 ids for this class must be manually assigned before calling save()相关推荐
- ids for this class must be manually assigned before calling save(): com.jia.enity.Book;
报错: ids for this class must be manually assigned before calling save(): com.jia.enity.Book; nested e ...
- 错误信息:ids for this class must be manually assigned before calling save(): sample.db.Completedsample
错误信息:ids for this class must be manually assigned before calling save(): sample.db.Completedsample 原 ...
- 【转】 ids for this class must be manually assigned before calling save()
[转] ids for this class must be manually assigned before calling save().. 转自:http://blog.csdn.net/sof ...
- ids for this class must be manually assigned before calling save()报错解决方法
通常报出这个错误是因为实体主键未赋值导致的,未赋值主键无法执行save()方法. 解决方法: 在实体主键上加上 @GeneratedValue(strategy = GenerationType.AU ...
- ids for this class must be manually assigned before calling save():Xxx
把Xxx.hbm.xml主键生成策略改成identity 转载于:https://www.cnblogs.com/lanhj/p/4051428.html
- Lua 报错 PANIC: unprotected error in call to Lua API (no calling environment) 解决办法
问题表现 lua_State *L = lua_open(); /* opens Lua */ luaopen_base(L); /* opens the basic library */ luaop ...
- SAP MM 创建退货类型的公司间STO,报错 -No delivery type for returns processing assigned to item 00010-
SAP MM 创建退货类型的公司间STO,报错 -No delivery type for returns processing assigned to item 00010- 执行事务代码ME21N ...
- vue3.0引入ant-design-vue报错 export ‘default‘ (imported as ‘Vue‘) was not found in ‘vue‘
vue3.0引入ant-design-vue报错 export 'default' (imported as 'Vue') was not found in 'vue' 报错如下 解决办法 根目录命令 ...
- SAP VL02N 为DN分配HU号码报错之对策
SAP VL02N 为DN分配HU号码报错 - HU ### contains an item that cannot be assigned - 之对策 VL02N,进入包装界面,将某个HU号码分配 ...
最新文章
- 工业4.0:数字化供应链的三个方向
- 嵌入式VxWorks系统开发与应用
- OpenCV安装好了,show第一个例子,找找成就感~~~
- [hdu] 5696 区间的价值 || 序列分治
- hi3531交叉编译环境arm-hisiv100nptl-linux搭建过程
- 2016年4月 TIOBE 编程语言排行榜
- ES6个人小手册,走过路过不要错过。。。。。
- 配置IIS5.5/6.0 支持 Silverlight
- 基于摄像头循迹的电子设计竞赛论文
- app商品详情原数据 API ——淘宝/天猫
- 通过两个队列实现一个栈(C语言)
- 【IDEA】如何修改已创建的文件类型,虽然很无脑,但是也很棘手
- 测试用例以及相关问题
- win7如何设置以管理员身份运行程序
- Andriod Studio下载安装教程
- 报错UnicodeDecodeError ‘gbk‘ codec can‘t decode byte 0x93 in position 7104 illegal multibyte sequence
- Leetcode_121_Best Time to Buy and Sell Stock
- python发送esc_使用win32prin将一行文本发送到Python中的ESC/POS打印机
- Windows照片查看器无法显示此照片,因为计算机上的可用内存可能不足。
- 浅析计算机网络技术相关论文,计算机网络技术浅析论文 - 经典论文