File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes TransientObjectException of hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "TransientObjectException of hibernate" Watch "TransientObjectException of hibernate" New topic

TransientObjectException of hibernate

sardar waqas ahmed

Joined: Oct 19, 2011
Posts: 16

hi to every one. i am new to hibernate i am getting the following exception when want to add record in db .i go through diferent forum and try alot to fix the problem by adding annotation but didnot work kindly help me thanks in advance

this is exception

org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.hrms.persistanceLayer.HrAddress
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(
at org.hibernate.type.EntityType.getIdentifier(
at org.hibernate.type.ManyToOneType.isDirty(
at org.hibernate.type.ManyToOneType.isDirty(
at org.hibernate.type.TypeHelper.findDirty(
at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(
at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(
at org.hibernate.impl.SessionImpl.flush(
at org.hibernate.impl.SessionImpl.managedFlush(
at org.hibernate.transaction.JDBCTransaction.commit(
at com.hrms.controllerLayer.ServiceProvider.savePersonalInfoNormalUser(
at com.hrms.beans.PersonalInfoBean.saveHrPersonnalBasicInfo(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.el.parser.AstValue.invoke(
at org.apache.el.MethodExpressionImpl.invoke(
at com.sun.faces.facelets.el.TagMethodExpression.invoke(
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(
at com.sun.faces.application.ActionListenerImpl.processAction(
at javax.faces.component.UICommand.broadcast(
at javax.faces.component.UIData.broadcast(
at javax.faces.component.UIViewRoot.broadcastEvents(
at javax.faces.component.UIViewRoot.processApplication(
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(
at com.sun.faces.lifecycle.Phase.doPhase(
at com.sun.faces.lifecycle.LifecycleImpl.execute(
at javax.faces.webapp.FacesServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.valves.AccessLogValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.AbstractHttp11Processor.process(
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
at java.util.concurrent.ThreadPoolExecutor$
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Did you try adding the @Transient in the attributes of you class that will not be persisted? Could you post your code?

[] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Why would you add the @Transient annotation? Then it will not be persisted. I don't think that is what he wants.

I would do what the exceptions says: save the transient instance before flushing: com.hrms.persistanceLayer.HrAddress. You're trying to persist an entity but that entity references another entity (of type HrAddress) which hasn't been persisted yet. Try to persist that first.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
sardar waqas ahmed

Joined: Oct 19, 2011
Posts: 16
@Wouter Oet

i dont want to persist HrAddress yet how i can set this entity that hibernate allowed me to save HrAddress as null in parent entity

i have two table HrPerson and HrAddress. HrPerson hold the foriegn key of address and one to many releationship. now when i only want to save HrPerson then it gave me above exception. is there need to change the hbm file of HrPerson or something else thanks
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Leave HrAddress null. Then after you persisted the entity create a new HrAddress, persist it and assign it to the entity.
I agree. Here's the link:
subject: TransientObjectException of hibernate
It's not a secret anymore!