-->
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.  [ 2 posts ] 
Author Message
 Post subject: Re-posted : Record versionning
PostPosted: Sat Jul 26, 2008 3:36 pm 
Newbie

Joined: Sun Jun 22, 2008 1:57 pm
Posts: 11
Sorry, I posted it in the wrong forum. Because I partially found the answer, I post it again with the answer. I hope it will help others.

C-Rock
----------------------------------------------------

Hi,

When I insert new records to the database, the "version" field is assigned with the version "1" - I checked the object property value and that's what I expected- and when I commit the field in the DB is null !!!???

I used the generated="always" to avoid yo manage it manually (see the hbm.xml I pasted below). The generator works fine but not the version...

Is someone able to explain why the object property works fine but the field is null in the database?

Hibernate version: 1.2 for .NET 2.0

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping  xmlns="urn:nhibernate-mapping-2.2" assembly="DataLayer" namespace="DataLayer.DataObjects">
  <class name="FREQUENCY" table="FREQUENCY" optimistic-lock="version" dynamic-update="true" dynamic-insert="true" >
    <id name="FREQUENCY_OID" column="FREQUENCY_OID" type="Int32">
      <generator class="hilo" />
    </id>
    <version column="FREQUENCY_RECORD_VERSION" name="FREQUENCY_RECORD_VERSION" type="Int32" generated="always" />
    <property name="FREQUENCY_CODE" type="String" length="15" not-null="true"/>
    <property name="FREQUENCY_DESCRIPTION" type="String" length="80" not-null="true"/>
    <property name="FREQUENCY_VALUE" type="Int32" not-null="true"/>
    <property name="FREQUENCY_UNIT" type="String" length="8" not-null="true"/>
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
transaction.Begin();
foreach (String frequency in frequencies)
{
     // frequency.FREQUENCY_RECORD_VERSION = null

     // Insertion
     transaction.Save(frequency);

    // frequency.FREQUENCY_RECORD_VERSION  =1
}
transaction.Commit();

[b]// But the field in the database is null!!![/b]


Name and version of the database you are using: SQL Server 2005


Last edited by C-Rock on Sat Jul 26, 2008 3:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 26, 2008 3:39 pm 
Newbie

Joined: Sun Jun 22, 2008 1:57 pm
Posts: 11
Hi,

After some long and hard debuging (I'm a newbie with C# and Hibernate), I found that a versionning field with the attribute generated="always" set the hibernate flags generatedinsert to true and insert to false.

The "insert" flag filters fields added to the insert SQL statement, thus the versionning field is not inserted whith this mapping. It is inserted only when generated="never'. And in both cases, the object version number is correctly incremented, I found differences only about the insertion in the database.

I must be frank, I did not understand at all, but now its works. If someone can explain how it works and What I did not understood about the generated attribute it will be really appreciate.

C-Rock


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