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.  [ 7 posts ] 
Author Message
 Post subject: Doubt
PostPosted: Mon Dec 04, 2006 7:34 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
This code make always an update, even if i add a new record; if i change SaveOrUpdate to Save, all works (even updates)

in another solution with DB2/400 the same code (with SaveOrUpdate!)
works fine.

is it correct or not ? could be an oracle dialect bug?

thanks
regards

p.s : renamed namespace and class for readibility

Hibernate version: 1.2.0 beta 2

Mapping documents:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
<class name='MyNS.MyClass, MyNS' table='CC_TIPICTRL' lazy='false'>
<id name='ID' column='CCTCID'>
<generator class='assigned' />
</id>
<property name='Description' column='CCTCDESC' />
<property name='HasList' column='CCTCLISTA' />
<property name='HasValue' column='CCTCVALORE' />
<property name='IsContainer' column='CCTCCONTIENE' />
<property name='ControlClass' column='CCTCCLASSE' />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
foreach (MyClass ctrl in dgvControls.DataSource as BindableList<MyClass>)
{
this.m_session.SaveOrUpdate(ctrl);
}
this.m_session.Flush();
Full stack trace of any exception that occurs:
in NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\AdoNet\Expectations.cs:riga 29
in NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\NonBatchingBatcher.cs:riga 37
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 C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Persister\Entity\AbstractEntityPersister.cs:riga 1848
in NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Persister\Entity\AbstractEntityPersister.cs:riga 1749
in NHibernate.Impl.ScheduledUpdate.Execute() in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\ScheduledUpdate.cs:riga 64
in NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3299
in NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3278
in NHibernate.Impl.SessionImpl.Execute() in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3230
in NHibernate.Impl.SessionImpl.Flush() in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3066
in CartellaClinica.Admin.frmControls.kbSave_Click(Object sender, EventArgs e) in C:\Documents and Settings\luke\Documenti\Visual Studio 2005\Projects\CartellaClinica\CartellaClinica.Admin\frmControls.cs:riga 60
Name and version of the database you are using: Oracle 10g

Debug level Hibernate log excerpt:
2006-12-04 12:10:11,736 [10] DEBUG NHibernate.Impl.SessionImpl - executing flush
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister - Updating entity: [CartellaClinica.Domain.ClinicalFolderControlType#xxxxx]
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands: 1
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: UPDATE CC_TIPICTRL SET CCTCDESC = ?, CCTCLISTA = ?, CCTCVALORE = ?, CCTCCONTIENE = ?, CCTCCLASSE = ? WHERE CCTCID = ?
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister - Dehydrating entity: [CartellaClinica.Domain.ClinicalFolderControlType#xxxxx]
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Type.StringType - binding 'xxx' to parameter: 0
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Type.ByteType - binding '1' to parameter: 1
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Type.ByteType - binding '0' to parameter: 2
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Type.ByteType - binding '1' to parameter: 3
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Type.StringType - binding 'zzzzzzz' to parameter: 4
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.Type.StringType - binding 'xxxxx' to parameter: 5
2006-12-04 12:10:11,752 [10] DEBUG NHibernate.SQL - UPDATE CC_TIPICTRL SET CCTCDESC = :p0, CCTCLISTA = :p1, CCTCVALORE = :p2, CCTCCONTIENE = :p3, CCTCCLASSE = :p4 WHERE CCTCID = :p5; :p0 = 'xxx', :p1 = '1', :p2 = '0', :p3 = '1', :p4 = 'zzzzzzz', :p5 = 'xxxxx'
2006-12-04 12:10:11,783 [10] DEBUG NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands: 0
2006-12-04 12:10:11,815 [10] ERROR NHibernate.Impl.SessionImpl - could not synchronize database state with session
NHibernate.StaleStateException: Unexpected row count: 0; expected: 1
in NHibernate.AdoNet.Expectations.BasicExpectation.VerifyOutcomeNonBatched(Int32 rowCount, IDbCommand statement) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\AdoNet\Expectations.cs:riga 29
in NHibernate.Impl.NonBatchingBatcher.AddToBatch(IExpectation expectation) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\NonBatchingBatcher.cs:riga 37
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 C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Persister\Entity\AbstractEntityPersister.cs:riga 1848
in NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Persister\Entity\AbstractEntityPersister.cs:riga 1749
in NHibernate.Impl.ScheduledUpdate.Execute() in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\ScheduledUpdate.cs:riga 64
in NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3299
in NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3278
in NHibernate.Impl.SessionImpl.Execute() in C:\Documents and Settings\luke\Documenti\Riferimenti VS2005\NHibernate\NHibernate\Impl\SessionImpl.cs:riga 3221


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 2:36 pm 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
now the doubt is a problem : now i need to SaveOrUpdate my entity that have a bag, and if I call a Session.Update(obj) I'm getting an error because some entities in the bag could be new and need a Save instead an Update.

How can I do ? Is it an Oracle dialect bug ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 3:18 am 
Newbie

Joined: Tue May 18, 2004 10:51 am
Posts: 9
Location: Bolivia
Have you tried.



Code:
sess = factory.OpenSession()
tx  = sess.beginTransation();
foreach (MyClass ctrl in dgvControls.DataSource as BindableList<MyClass>)
{
this.m_session.SaveOrUpdate(ctrl);
}
tx.commit();
this.m_session.Flush();



what i mean is to put your code in a transaction.

Saludos,
-Rory[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 4:32 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
even within a Transaction give the same error: if i made only updates all works, but if I insert a new record, it try an update an give the error...

I think it's a bug


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 5:16 am 
Beginner
Beginner

Joined: Tue May 02, 2006 8:04 am
Posts: 34
<id name='ID' column='CCTCID'>
<generator class='assigned' />
</id>

You assign your own identifies, so NHibernate does not know if it has to insert or update it. Either add an unsaved value attribute which is necessary for SaveOrUpdate to work OR call insert or update instead of SaveOrUpdate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 5:28 am 
Regular
Regular

Joined: Thu May 11, 2006 12:30 pm
Posts: 72
sorry but I disagree :

- why the same application with DB2/400 Dialect works fine with SaveOrUpdate() and the same mapping ?

- I assign the ID myself, but NH should know if an entity is persisted or is new, as I can understand from documentation


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 07, 2006 5:49 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
If you have an object with ID 2 and an object with ID 3, how do you tell which one exists in the database and which one doesn't, without accessing the database? NHibernate can't.

You can add a timestamp or version column to aid NHibernate in determining this.

As to why it works on DB2/400, you are probably not testing with the same code or the same data on DB2.


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