org.hibernate.id.IdentifierGenerationException: 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(): com.zh.hibernate.subclass.Person
    at org.hibernate.id.Assigned.generate(Assigned.java:52)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
    at com.zh.hibernate.subclass.SubclassTest.testSave(SubclassTest.java:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

错误原因:在映射文件中,id设置的类别为assigned,不符合我的数据库MySql本身的设置。

改错:

     现在我将其属性改成 native 之后 就可以了    目前还没有遇到其他原因导致的这样的错误。之后遇到会及时更新

时间: 2024-11-06 02:15:53

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()的相关文章

Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.qingmu.seller.entity.OrderMaster

org.springframework.orm.jpa.JpaSystemException: ids for this class must be manually assigned before calling save(): com.qingmu.seller.entity.OrderMaster; nested exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be m

Hibernate: ids for this class must be manually assigned before calling save():

原文: http://blog.csdn.net/softimes/article/details/7008875 引起问题的原因: 由Hibernate根据数据库表自动生成的"类名.hbm.xml"映射文件引起的. 首先我的表(Info)由两个字段组成,即: int id;//主建 String name; (自己做测试,所以就简单的建了个表) 由Hibernate生成的Info.hbm.xml中是这样写的: -------------------------------------

【排坑记录】ids for this class must be manually assigned before calling save():

今天在做好友请求删除 接受的时候,能显示好友列表,后端逻辑都正常,但点删除按钮,就是出现上述错误. 先百度了,字面意思,id 保存前要先初始化.[我这都已经存在这个Id了,况且点的是删除按钮.] 然后我开始排查,检查前端代码,传参,请求url都能对上,所覆盖的innerHTML 也正确,没有出现问题[问题就在这,前端是正确的,但后端用的属性没对应上,出错了]. 然后SpringBootTest 自己传参进去,能查出来,请求逻辑没错. 调用请求的时候,输出了对象,发现对象的Id 值为 Undifi

org.hibernate.id.IdentifierGenerationException错误解决方法

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): ID主键生成策略为assigned 由应用程序负责生成主键标识符 <id name="id" type="java.lang.String"> <column name="ID" length=&qu

org.hibernate.id.IdentifierGenerationException: id

Spring mvc 用POI 导入Excel数据的时候提示:org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(). 原因:检查之后发现是因为Excel的数据格式不对.应该是文本,但是表格显示数据是常规.所以大家如果有遇到类似的问题要看一下是否是自己要导入的Excel格式不对,

hibernate ID 生成方式

1.assigned 主键由外部程序负责生成,在 save() 之前必须指定一个.Hibernate不负责维护主键生成.与Hibernate和底层数据库都无关,可以跨数据库.在存储对象前,必须要使用主键的setter方法给主键赋值,至于这个值怎么生成,完全由自己决定,这种方法应该尽量避免. <id name="id" column="id"> <generator class="assigned" /> </id&g

Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values;

项目部署,启动过程中有以下警告: [WARN]: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUIDGenerator instead 查看项目中用户类的主键生成策略: @GenericGenerator(name = "system-uuid", strategy

【hibernate】主键生成策略使用UUID报出如下警告:org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values;

主键生成策略使用UUID报出如警告如下: 控制台- 2017-11-24 18:40:14 [restartedMain] WARN org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values; consider using org.hibernate.id.UUI

hibernate ID生成策略配置

1.Student.hbm.xml配置 <hibernate-mapping package="com.wxh.hibernate.model"> <class name="Student" > <id name="id"> <generator class="uuid"></generator> </id> <property name="