java - Hibernate: org.hibernate.AssertionFailure: null id in com.xxx.Bean entry -


i faced following error:

com.google.gwt.user.server.rpc.unexpectedexception: service method 'public abstract void com.xxx.service.save(com.xxx.bean)' threw unexpected exception: org.hibernate.assertionfailure: null id in com.xxx.bean entry (don't flush session after exception occurs)     @ com.google.gwt.user.server.rpc.rpc.encoderesponseforfailure(rpc.java:385)     @ com.google.gwt.user.server.rpc.rpc.invokeandencoderesponse(rpc.java:588)     @ com.google.gwt.user.server.rpc.remoteserviceservlet.processcall(remoteserviceservlet.java:208)     @ com.google.gwt.user.server.rpc.remoteserviceservlet.processpost(remoteserviceservlet.java:248)     @ com.google.gwt.user.server.rpc.abstractremoteserviceservlet.dopost(abstractremoteserviceservlet.java:62)     @ javax.servlet.http.httpservlet.service(httpservlet.java:641)     @ javax.servlet.http.httpservlet.service(httpservlet.java:722)     @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:306)     @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210)     @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:240)     @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:161)     @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:496)     @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:164)     @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:100)     @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:541)     @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118)     @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:383)     @ org.apache.coyote.http11.http11processor.process(http11processor.java:243)     @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:188)     @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:166)     @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:288)     @ java.util.concurrent.threadpoolexecutor$worker.runtask(threadpoolexecutor.java:886)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:908)     @ java.lang.thread.run(thread.java:680) caused by: org.hibernate.assertionfailure: null id in com.xxx.bean entry (don't flush session after exception occurs)     @ org.hibernate.event.def.defaultflushentityeventlistener.checkid(defaultflushentityeventlistener.java:82)     @ org.hibernate.event.def.defaultflushentityeventlistener.getvalues(defaultflushentityeventlistener.java:190)     @ org.hibernate.event.def.defaultflushentityeventlistener.onflushentity(defaultflushentityeventlistener.java:147)     @ org.hibernate.event.def.abstractflushingeventlistener.flushentities(abstractflushingeventlistener.java:219)     @ org.hibernate.event.def.abstractflushingeventlistener.flusheverythingtoexecutions(abstractflushingeventlistener.java:99)     @ org.hibernate.event.def.defaultflusheventlistener.onflush(defaultflusheventlistener.java:50)     @ org.hibernate.impl.sessionimpl.flush(sessionimpl.java:1216)     @ org.hibernate.impl.sessionimpl.managedflush(sessionimpl.java:383)     @ org.hibernate.transaction.jdbctransaction.commit(jdbctransaction.java:133)     @ com.xxx.serviceimpl.save(serviceimpl.java:32)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     ... 23 more 

here mysql table definition:

create table `tblarf` (   `arf_id` bigint(19) not null auto_increment,   `arf_manufacturer_mnf_id` bigint(19) not null,   ...   primary key (`arf_id`),   key `arf_manufacturer_mnf_id` (`arf_manufacturer_mnf_id`) ) 

and here hibernate mapping:

<class name="bean" table="tblarf">   <id name="key" type="long" unsaved-value="null">     <column name="arf_id" not-null="true"/>     <generator class="identity" />   </id> <many-to-one column="arf_manufacturer_mnf_id" name="manufacturer"     class="manufacturerbean" not-null="true" lazy="false"/> ... </class> 

java code:

session s = hibernate.getcurrentsession(); transaction t = s.begintransaction(); s.merge(bean.getmanufacturer()); s.save(bean); t.commit(); 

i noticed if remove key arf_manufacturer_mnf_id (arf_manufacturer_mnf_id) assertionfailure doesn't happen. there way avoid error without removing key?

this solution doesn't work me unfortunately.

the answer found here: https://forum.hibernate.org/viewtopic.php?f=1&t=1009141

'order' reserved keyword in sql if want use if column name needs quoted. see http://docs.jboss.org/hibernate/core/3.6/reference/en-us/html/mapping.html#mapping-quotedidentifiers instructions how enabled this.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -