Hi,
I am using Hibernate as a persistence provider in a web application. I have a Customer and CustomerType POJO with surrogate keys (systemId of type java.lang.Long). Customer contains an instance of CustomerType, and the user can select the customer type using a drop-down list from a JSF page. The systemId of the customer type is placed in the systemId of the inner bean of CustomerType inside Customer. When I attempt to save the Customer with the systemId inside the CustomerType, I get an exception (shown at the end)
Apparently hibernate does not find that the CustomerType object to be persistent even though it has a systemId which is the id in the mapping and attempts to save it but fails because I have cascade="none". When I fetch the CustomerType from the database using the systemId before saving, it works.
Do I always have to fetch the CustomerType using the systemId and place it inside the Customer ? or can I just use the systemId? I know this worked before. I am now using Hibernate 3.6.0 Final.
Note: I have lazy="false" for the CustomerType
Regards,
Talha
The exception is as follows: Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: org.mohd.bend.security.beans.SystemUser at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:243) at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456) at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:265) at org.hibernate.type.ManyToOneType.isDirty(ManyToOneType.java:275) at org.hibernate.type.TypeHelper.findDirty(TypeHelper.java:295) at org.hibernate.persister.entity.AbstractEntityPersister.findDirty(AbstractEntityPersister.java:3378) at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:520) at org.hibernate.event.def.DefaultFlushEntityEventListener.isUpdateNecessary(DefaultFlushEntityEventListener.java:230) at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:154) at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219) at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
|