-->
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.  [ 6 posts ] 
Author Message
 Post subject: TransientObjectException
PostPosted: Thu Oct 13, 2005 4:20 pm 
Newbie

Joined: Thu Oct 13, 2005 4:11 pm
Posts: 1
Hi all,

I've been having an issue with NHibernate where I get an object from one session, and try to use that object as a parameter in an HQL query on a different session where that object filters data. I get a TransientObjectException, and it tells me to save the object before I try to use it. This used to work, but after upgrading to 1rc3 it has stopped working. I'm wondering if this is the expected functionality, and it was wrong before, or if it is wrong now.

I can think of several workarounds. One is to save the object (but there are no changes, so it just wastes processing time). The other is to get a new object on the new session using the ID from the old object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 4:31 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please post the details (code, mappings), I will have a look.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 8:57 am 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
I'm working with shiznit, here is a sample of the code (removed unrelated code). Search this sample for "<--- TransientObjectException"

By the way, this started when we moved from 0.9.0.0 to 1.0.

Code:
public class Export : IActivity
{
   //...

   public void Do(IDictionary parameters)
   {
      PayerGroup pg = (PayerGroup)parameters["PayerGroup"]; //A nhibernate mapped object, passed in from another session.

      ISession session = null;

      try
      {
         session = GetASession(); //simplified fake code
         
         IList results = session.CreateQuery("FROM ... WHERE x.PayerGroup = :PayerGroup")
            .SetParameter("PayerGroup", pg)  //<--- TransientObjectException
            .List();
            
         //...
      }
      finally
      {
         //...
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 12:16 pm 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
Stack Trace
----------------
NHibernate.ADOException: Could not execute query ---> NHibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: CDR.Wopper.DomainModel.PayerGroup
at NHibernate.Impl.SessionImpl.ThrowTransientObjectException(Object obj)
at NHibernate.Impl.SessionImpl.GetEntityIdentifierIfNotUnsaved(Object obj)
at NHibernate.Type.EntityType.GetIdentifier(Object value, ISessionImplementor session)
at NHibernate.Type.ManyToOneType.NullSafeSet(IDbCommand cmd, Object value, Int32 index, ISessionImplementor session)
at NHibernate.Hql.QueryTranslator.BindNamedParameters(IDbCommand ps, IDictionary namedParams, Int32 start, ISessionImplementor session)
at NHibernate.Loader.Loader.PrepareQueryCommand(SqlString sqlString, QueryParameters parameters, Boolean scroll, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Hql.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
--- End of inner exception stack trace ---
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List()
at CDR.Wopper.ClientSpecific.Highmark.Export.Do(IDictionary parameters) in c:\code\wopper\cdr.wopper\clientspecific\highmark\export.cs:line 52
at CDR.Wopper.Client.Clients.ImportExportForm.PerformActivity(IActivity activity, PayerGroup payerGroup, Boolean testing) in C:\Code\Wopper\CDR.Wopper.Client\Clients\ImportExportForm.cs:line 377
at CDR.Wopper.Client.Clients.ImportExportForm.grid_ClickCellButton(Object sender, CellEventArgs e) in C:\Code\Wopper\CDR.Wopper.Client\Clients\ImportExportForm.cs:line 388
at Infragistics.Win.UltraWinGrid.UltraGrid.OnClickCellButton(CellEventArgs e)
at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e)
at Infragistics.Win.UltraWinGrid.UltraGridCell.OnButtonClick()
at Infragistics.Win.UltraWinGrid.CellButtonUIElement.OnClick()
at Infragistics.Win.ControlUIElementBase.ProcessMouseUp(Object sender, MouseEventArgs e)
at System.Windows.Forms.Control.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 8:22 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
This problem may be due to the fact that the session guess the unsaved value of PayerGroup's identifier (and it is the value of your pg instance).

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 8:30 am 
Contributor
Contributor

Joined: Thu Jun 23, 2005 1:08 pm
Posts: 32
Location: Baltimore, MD
That makes sense, but the identifier on that instance is a Guid, and it's not Guid.Empty (it came from the database, just a diffreent session). I looked through the code and did see some changes to that code, but it moslty just looked like reoganizing, I haven't spotted anything that looks like it could be the problem yet.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.