-->
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.  [ 8 posts ] 
Author Message
 Post subject: UPDATE instead SELECT
PostPosted: Tue May 15, 2007 4:59 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
The error is "could not update", but the real question is : why UPDATE ?
This is a simple SELECT query, but NH create an UPDATE clause...

Hibernate version:
1.2.0.GA
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
  <class name="FinitenessEvo.Domain.OrdineDiLavoro, FinitenessEvo.Domain" table="detcom" >
    <composite-id>
      <key-property name="CodiceCliente" column="clicod" />
      <key-property name="Anno" column="coanno"/>
      <key-property name="Numero" column="conume"/>
    </composite-id>
    <property name="NoteScheda" column="codnot" />
    <property name="FlagChiusura" column="codchi" />
    <property name="OreTotali" column="codte1" />
    <property name="MinutiTotali" column="codte2" />
    <property name="OreOriginali" column="codore" />
    <property name="MinutiOriginali" column="codmin" />
    <property name="Stato" column="codstx" />
    <property name="RiferimentoCliente" column="codacl" />
    <property name="DataRichiesta" column="codatr" />
    <property name="DataConsegnaPrevista" column="codaco" />
    <property name="DataComunicazioneCliente" column="codcom" />
    <property name="MatricolaAccettante" column="codacc" />
    <property name="MatricolaAutorizzazione" column="codaut" />
    <property name="TipoIntervento" column="codtip" />
    <property name="MatricolaSviluppatore" column="codpgm" />
    <property name="DataInizioLavori" column="codinl" />
    <property name="SchedaConsegna" column="codcon" />
    <property name="TipoTest" column="cotetp" />
    <property name="TestIntermedi" column="cotei1" />
    <property name="TestFinali" column="cotef1" />
    <property name="Testo" column="coddet" />
    <many-to-one class="FinitenessEvo.Domain.Commessa, FinitenessEvo.Domain" name="Commessa" not-found="ignore" lazy="proxy" >
      <column name="tlicod"/>
      <column name="tabann"/>
      <column name="tabcom"/>
    </many-to-one>
    <many-to-one class="FinitenessEvo.Domain.Cliente, FinitenessEvo.Domain" name="Cliente" column="clicod" insert="false" update="false" not-found="ignore" lazy="proxy" />
    <many-to-one class="FinitenessEvo.Domain.TipoIntervento, FinitenessEvo.Domain" name="ClsTipoIntervento" column="codtip" insert="false" update="false" not-found="ignore" lazy="proxy" />
    <many-to-one class="FinitenessEvo.Domain.Matricola, FinitenessEvo.Domain" name="ClsMatricolaSviluppatore" column="codpgm" insert="false" update="false" not-found="ignore" lazy="proxy" />
  </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
IQuery queryCommesseODL = this.m_session.CreateQuery("from OrdineDiLavoro as odl where odl.MatricolaSviluppatore=:dev");
queryCommesseODL.SetString("dev", mat.Codice);
foreach (OrdineDiLavoro odl in queryCommesseODL.List<OrdineDiLavoro>())
{}

Full stack trace of any exception that occurs:
Code:
   in NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
   in NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
   in NHibernate.Impl.ScheduledUpdate.Execute()
   in NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
   in NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
   in NHibernate.Impl.SessionImpl.Execute()
   in NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces)
   in NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
   in NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
   in NHibernate.Impl.SessionImpl.Find[T](String query, QueryParameters parameters)
   in NHibernate.Impl.QueryImpl.List[T]()
   in FinitenessEvo.GUI.frmShowGantt.RefreshUsers() in C:\Documents and Settings\luke\Desktop\FinitenessEvo\Finiteness Evo\frmShowGantt.cs:riga 326
   in FinitenessEvo.GUI.frmShowGantt.frmShowGantt_Load(Object sender, EventArgs e) in C:\Documents and Settings\luke\Desktop\FinitenessEvo\Finiteness Evo\frmShowGantt.cs:riga 39
   in System.Windows.Forms.Form.OnLoad(EventArgs e)
   in System.Windows.Forms.Form.OnCreateControl()
   in System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   in System.Windows.Forms.Control.CreateControl()
   in System.Windows.Forms.Control.WmShowWindow(Message& m)
   in System.Windows.Forms.Control.WndProc(Message& m)
   in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   in System.Windows.Forms.ContainerControl.WndProc(Message& m)
   in System.Windows.Forms.Form.WmShowWindow(Message& m)
   in System.Windows.Forms.Form.WndProc(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   in System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   in System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
   in System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
   in System.Windows.Forms.Control.CreateHandle()
   in System.Windows.Forms.Form.CreateHandle()
   in System.Windows.Forms.Control.get_Handle()
   in System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   in System.Windows.Forms.Control.Show()
   in FinitenessEvo.GUI.frmHome.menuProgrammazioneGantt_Click(Object sender, EventArgs e) in C:\Documents and Settings\luke\Desktop\FinitenessEvo\Finiteness Evo\frmHome.cs:riga 56
   in FinitenessEvo.GUI.frmHome.toocmdGantt_Click(Object sender, EventArgs e) in C:\Documents and Settings\luke\Desktop\FinitenessEvo\Finiteness Evo\frmHome.cs:riga 93
   in System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   in System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   in System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   in System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   in System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
   in System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
   in System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   in System.Windows.Forms.Control.WndProc(Message& m)
   in System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   in System.Windows.Forms.ToolStrip.WndProc(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   in System.Windows.Forms.Application.Run(Form mainForm)
   in FinitenessEvo.GUI.Program.Main() in C:\Documents and Settings\luke\Desktop\FinitenessEvo\Finiteness Evo\Program.cs:riga 32
   in System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
   in System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
   in System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
   in System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
   in System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
   in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
   in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   in System.Threading.ThreadHelper.ThreadStart()

Name and version of the database you are using:
Microsoft SQL Server 2005
The generated SQL (show_sql=true):
Code:
{UPDATE detcom SET codnot = ?, codchi = ?, codte1 = ?, codte2 = ?, codore = ?, codmin = ?, codstx = ?, codacl = ?, codatr = ?, codaco = ?, codcom = ?, codacc = ?, codaut = ?, codtip = ?, codpgm = ?, codinl = ?, codcon = ?, cotetp = ?, cotei1 = ?, cotef1 = ?, coddet = ?, tlicod = ?, tabann = ?, tabcom = ? WHERE clicod = ? AND coanno = ? AND conume = ?}


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 6:33 am 
Newbie

Joined: Thu Aug 10, 2006 12:27 pm
Posts: 8
It looks to me that NH decided it needed to flush some dirty objects before doing the SELECT. There are various conditions when NH does the auto flush (and it also depends on your flush mode).

In any case, when it did the flush the update failed so it never got to your select I guess.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 6:42 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
but this is the first statement of the application, it didn't anything before;
I try to put a session.Clear() before the creation of the query, but NH generate always an UPDATE


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 4:13 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
no idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:33 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
I found the cause of the problem but I cannot understand why it happens

I add to my mapping file dynamic-update='true' to see what NH try to update, and now the UPDATE clause changed to this

Code:
{UPDATE detcom SET codcom = ? WHERE clicod = ? AND coanno = ? AND conume = ?}


then I search my data to see what's the problem and I see that codcom contains NULL (it's a datetime field)

Investigating i found that NH try to UPDATE all records where codcom,codatr or codaco contains NULL, other records give no errors...

Why ???!

Mine is a SELECT query, why NH try an UPDATE ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 4:41 am 
Regular
Regular

Joined: Wed Apr 25, 2007 4:18 am
Posts: 51
Location: Belarus, Gomel
Hi berets!

What does your class look like? Especially DataComunicazioneCliente property - do you use Nullable type (DateTime?) I suppose the problem may be there,

_________________
WBR, Igor


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 6:45 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
hi IgorK,
yes I use a DateTime, is a problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 4:06 am 
Regular
Regular

Joined: Wed Apr 25, 2007 4:18 am
Posts: 51
Location: Belarus, Gomel
Hi berets!

As you table may contain null dates, you have to use DateTime?
Maybe you misread question mark, it is a shortcut for type Nullable<DateTime>.
AFAIK "plain" DateTime will represent your null date as something like 01/01/0001 - and NHibernate will try to save it during session flush.
BTW you have to check all your code that refer this property, as it will have to use some extra processing. Or maybe you can create helper property - to access this Nullable datetime and convert DateTime.MinVale to null (I suppose you don't need such a date).

_________________
WBR, Igor


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