-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Using Identifiers in many-to-one relations
PostPosted: Tue Feb 15, 2011 11:49 am 
Newbie

Joined: Tue Feb 15, 2011 11:38 am
Posts: 2
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)


Top
 Profile  
 
 Post subject: Re: Using Identifiers in many-to-one relations
PostPosted: Tue Feb 15, 2011 12:50 pm 
Newbie

Joined: Tue Feb 15, 2011 11:38 am
Posts: 2
I just solved the problem. I added Integer version = 0 to the constructor of the POJOs, and hibernate does not execute selects before inserting.


Top
 Profile  
 
 Post subject: Re: Using Identifiers in many-to-one relations
PostPosted: Sun Sep 22, 2013 12:56 pm 
Newbie

Joined: Thu Sep 19, 2013 2:34 pm
Posts: 2
I have the same problem. Can you please explain how to resolve it using an exampl

My Email id vbsenthilinnet@gmail.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.