-->
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: Using Joined-subclass and replicate
PostPosted: Tue Apr 25, 2006 8:22 am 
Newbie

Joined: Tue Apr 25, 2006 7:57 am
Posts: 3
I am using an extra database, and want to replicate data from one database to another using nhibernate.
Each database has its own sessionFactory, and connection.

First I save the data in the first database using the standard Save method, and replicated data with the Replicate method, with the option Overwrite set.

This approach works for all my objects, except those who use the joined-subclass tag in the hbm.xml file. I can perfectly save these objects using the Save method, but when invoking the Replicate method an error happens. The error claims that the specific version of my joined-subclass does not exist in the database. I have visually inspected this, and the data is available.

Could it be an issue between joined-subclasses and the replicate method?

The error is as i can see identical to this old jira issue on the Java version
http://opensource.atlassian.com/projects/hibernate/browse/HB-609?page=history
Except i get an ADO exception using .net.

Hibernate version:
1.0.2.0

Mapping files
<class name="XXX.Class1, ComponentName" table="Class1">
<id name="DataId" column= "id" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
</class>

<joined-subclass name="XXX.menu, ComponentName" table="menu"
dynamic-update="false"
dynamic-insert="false"
extends="XXX.Class1, ComponentName">
<key column="parentpageid" />
<list name="MenusList" cascade="all">
<key column="menusid" />
<index column="posn" />
<one-to-many class="XXX.MenuItem, ComponentName" />
</list>
</joined-subclass>


<class name="XXX.MenuItem, ComponentName" table="menuitem">
<id name="DataId" column= "id" type="Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid" />
</id>
<property name="Name" column="name" type="String"/>

<list name="ItemModesList" cascade="all" table="mdfmenumode">
<key column="menuid" />
<index column="posn" />
<composite-element class="XXX.ItemModesElement, ComponentName">
<property name="Menu" column="menu" type="String"/>
<property name="Mode" column="mode" type="Int32"/>
</composite-element>
</list>
</class>

Code between sessionFactory.openSession() and session.close():
session = factory.OpenSession();
transaction = session.BeginTransaction();
session.Replicate(newObject.Version, ReplicationMode.Overwrite);
session.Replicate(newObject, ReplicationMode.Overwrite);
transaction.Commit();

Full stack trace of any exception that occurs:
at NHibernate.Persister.AbstractEntityPersister.GetCurrentVersion(Object id, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Replicate(Object obj, ReplicationMode replicationMode)
at NHibernate.Engine.Cascades.CascadingAction.ActionReplicateClass.Cascade(ISessionImplementor session, Object child, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.CascadeCollection(CascadingAction action, CascadeStyle style, PersistentCollectionType collectionType, IType elemType, Object child, CascadePoint cascadeVia, ISessionImplementor session, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything)
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IClassPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.Replicate(Object obj, ReplicationMode replicationMode)

Name and version of the database you are using:
SQLExpress

Thanks
SWJust


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 9:35 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This looks like a bug, please report it using NHibernate JIRA, preferably with a simple test case. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 2:59 am 
Newbie

Joined: Tue Apr 25, 2006 7:57 am
Posts: 3
Is there any possible workaround to my problem? except rewriting the core of my system.
I added a testcase to the Jira Issue NH-585


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 5:29 am 
Newbie

Joined: Thu Aug 31, 2006 3:35 am
Posts: 3
I have encountered this (or similar) problem in our project. It appears that AbstractEntityPersister generates version select statement on the right (base) table, but in selection fields and WHERE clause uses identifier columns of joined-subclass table.

I have a solution for this, that so far works with our project, but tight schedule on my project does not allow me to document it as a patch nor supply an unit test (I haven't done that before).

So I'm posting it here in hope that this solution will work for you as well and that there will be a qualified enough person to check the solution and probably integrate it in some build.

New property in Persister\Entity\AbstractEntityPersister.cs:
Code:
        // NH-585
        public virtual string[] VersionedIdentifierColumnNames
        {
            get { return rootTableKeyColumnNames; }
        }

Changed function in Persister\Entity\AbstractEntityPersister.cs:
Code:
      protected SqlString GenerateSelectVersionString()
      {
         SqlSimpleSelectBuilder builder = new SqlSimpleSelectBuilder( factory );
         builder.SetTableName( VersionedTableName );

         if( IsVersioned )
         {
            builder.AddColumn( VersionColumnName );
         }
         else
         {
                // NH-585
                // builder.AddColumns( IdentifierColumnNames );
            builder.AddColumns( VersionedIdentifierColumnNames );
         }

            // NH-585
            //builder.AddWhereFragment(IdentifierColumnNames, IdentifierType, " = ");
            builder.AddWhereFragment(VersionedIdentifierColumnNames, IdentifierType, " = ");

         return builder.ToSqlString();
      }

Overriden property in Persister\Entity\JoinedSubclassEntityPersister.cs:
Code:
        // NH-585
        // Returns an array of key column names of the base table (index 0)
        public override string[] VersionedIdentifierColumnNames
        {
            get { return naturalOrderTableKeyColumns[0]; }
        }


Best regards,
Andy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 5:48 am 
Newbie

Joined: Tue Apr 25, 2006 7:57 am
Posts: 3
Hi Andy,
Thanks for the reply, unfortunately we made a design change to make it work. The project which I was involved in is finished and delivered. But I’ll have this fix in mind, if I have the problem with Hibernate again.

Best Regards
SWJust


Top
 Profile  
 
 Post subject: Nhibernate bugado ainda
PostPosted: Wed Aug 15, 2007 2:19 pm 
Newbie

Joined: Wed Aug 15, 2007 2:08 pm
Posts: 1
a última versão do nhibernate ainda não está funcionando.. precisei baixar os fontes do NHibernate, alterar as classes que o Andy indicou.. gerar a dll.. aí q funcionou..

valeu!!


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.