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: DB2 timestamp as key
PostPosted: Fri Sep 29, 2006 8:55 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
i've a table with a single field primary key, the type of this field is timestamp; the problem is that when i save a new entity i'm getting a "Could not save object" error "Value cannot be null\r\n Parameter name : id"

when i quit the application instead the record was regularly saved with right timestamp key.

i tried changing generator class to native but nothing

any idea ?

thanks

Hibernate version: 1.2.0 Beta1

Mapping documents:

<id name ='ID' column ='IMPID'>
<generator class ='identity' />
</id>
<property name='UserID' column='IMPUSER' />
<property name='AppointmentDatetime' column='IMPDATE' />
.......

Full stack trace of any exception that occurs:
in NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) in C:\Documents and Settings\luke\Desktop\NHibernate Beta 1\NHibernate\Impl\SessionImpl.cs:riga 813
in NHibernate.Impl.SessionImpl.Save(Object obj) in C:\Documents and Settings\luke\Desktop\NHibernate Beta 1\NHibernate\Impl\SessionImpl.cs:riga 750
in NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) in C:\Documents and Settings\luke\Desktop\NHibernate Beta 1\NHibernate\Impl\SessionImpl.cs:riga 1581
in RuredilManager.frmImpegno.kbConfirm_Click(Object sender, EventArgs e) in C:\Documents and Settings\luke\Desktop\RuredilManager\RuredilManager\frmImpegno.cs:riga 91
in System.Windows.Forms.Control.OnClick(EventArgs e)
in ComponentFactory.Krypton.Toolkit.KryptonButton.OnClick(EventArgs e)
in ComponentFactory.Krypton.Toolkit.KryptonButton.OnButtonClick(Object sender, MouseEventArgs e)
in ComponentFactory.Krypton.Toolkit.ButtonController.OnClick(MouseEventArgs e)
in ComponentFactory.Krypton.Toolkit.ButtonController.MouseUp(Control c, Point pt, MouseButtons button)
in ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
in ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
in ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
in ComponentFactory.Krypton.Toolkit.ViewManager.MouseUp(MouseEventArgs e)
in ComponentFactory.Krypton.Toolkit.VisualControl.OnMouseUp(MouseEventArgs e)
in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
in System.Windows.Forms.Control.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.Form.ShowDialog(IWin32Window owner)
in System.Windows.Forms.Form.ShowDialog()
in RuredilManager.frmMain._ManageAppointment(String Description) in C:\Documents and Settings\luke\Desktop\RuredilManager\RuredilManager\frmMain.cs:riga 162
in RuredilManager.frmMain.schMain_AppointmentChanged(Object sender, AppointmentChangeEventArgs e) in C:\Documents and Settings\luke\Desktop\RuredilManager\RuredilManager\frmMain.cs:riga 195
in Janus.Windows.Schedule.AppointmentChangeEventHandler.Invoke(Object sender, AppointmentChangeEventArgs e)
in Janus.Windows.Schedule.Schedule.OnAppointmentChanged(AppointmentChangeEventArgs e)
in Janus.Windows.Schedule.Schedule.a(ScheduleAppointment , AppointmentChange )
in Janus.Windows.Schedule.ScheduleAppointment.set_Text(String value)
in Janus.Windows.Schedule.Schedule.a(JNSN )
in Janus.Windows.Schedule.Schedule.w()
in Janus.Windows.Schedule.Schedule.y()
in Janus.Windows.Schedule.JNSN.ProcessDialogKey(Keys keyData)
in System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
in System.Windows.Forms.Control.PreProcessMessage(Message& msg)
in System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
in System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
in System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(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 RuredilManager.Program.Main() in C:\Documents and Settings\luke\Desktop\RuredilManager\RuredilManager\Program.cs:riga 17
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:DB2 UDB for iSeries


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 9:31 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
I certainly hope that you can change this.

Having a timestamp as a primary key is a good way to ensure that your project fails. This completely obliterates any possibility of concurrency.

Rather than try and work around getting nhibernate to do your bidding, you should really question the design and see if you can create a surrogate key (I know this is sometimes hard). This will save you lots of pain and headaches in the future (especially with NHibernate).

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 9:42 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
and the reason it's not working is probably because you have your <id> element set to "identity", which is the auto-incremented integer generated by the database. This maps to an int in your object.

I'm not sure about DB2, but read up on the docs and see what types of generators are available to you, and pick one of those.

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 9:52 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
i'm trying to use a data type that autogenerate a value in the DBMS, but DB2/400 support only timestamp and rowid; i'm trying now with rowid, but with nh i've the same problem, which king of generator should i use ?
i tried all but nothing


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 9:54 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
http://www.hibernate.org/hib_docs/nhibe ... aration-id

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 10:03 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
ok ,i found that ROWID data type is a good way, but with all generator classes i'm getting error! by the way records in the DB were saved!

i sure use a varchar key field and generate a GUID by the code, but i prefer leave this job to DBMS


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 11:14 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
verify that the type in your table, mapping, and class are all compatible. What class is throwing that error? Is it ADO or NHibernate?

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 29, 2006 11:25 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
the error is from NHibernate, "Value cannot be null" if i set generator class=identity, idem if i set native, type mismatch if i use guid...


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.