-->
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: NHibernateUtil.Initialize problem
PostPosted: Mon May 29, 2006 5:33 am 
Newbie

Joined: Mon Jan 16, 2006 12:59 pm
Posts: 5
Location: Zagreb, Croatia
Hi,

using NHib 1.1 with VS 2005.


I wanted to use .NET 2.0 generics in my entity classes so consider the following example class:


<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Bss.AppFramework.Common.Catalog.Admin.CatalogApplicationEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" table="Application">
<id name="Id" column="ApplicationId" type="System.Int32" unsaved-value="-1" access="nosetter.camelcase-underscore">
<generator class="native" />
</id>

<version name="Version" unsaved-value="undefined"/>

<property name="ModifiedTime" column="ModifiedTime" type="NHibernate.Nullables2.NullableDateTimeType, NHibernate.Nullables2"/>
<property name="CreatedTime" column="CreatedTime" type="NHibernate.Nullables2.NullableDateTimeType, NHibernate.Nullables2"/>
<property name="CreatedUser" column="CreatedUser" />
<property name="ModifiedUser" column="ModifiedUser" />

<property name="Name" column="Name" />


<property name="PasswordExpirationPeriod" column="PasswordExpirationPeriod" />
<property name="UserSessionExpirationPeriod" column="UserSessionExpirationPeriod" />



<property name="License" column="License" access="nosetter.camelcase-underscore"/>



<bag name="Menu" cascade="all" access="field.camelcase-underscore"
lazy="true" inverse="true" order-by="`Index`" >
<key column="ApplicationId" />


<one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogMenuEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
</bag>

<bag name="_roles" cascade="all-delete-orphan" access="field.camelcase-underscore"
lazy="true" inverse="true" >
<key column="ApplicationId" />


<one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogRoleEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
</bag>


</class>
</hibernate-mapping>


public class CatalogApplicationEntity
{

private IList _roles;
private IList<RoleEntity> _genericRoles;

public IList<RoleEntity> Roles
{
get
{
EntityCollection<RoleEntity> roles = _genericRoles as EntityCollection<RoleEntity>;

if ((_roles != null) && ((roles == null) || roles.InnerList != _roles))
{
roles = new EntityCollection<CatalogRoleEntity>(_roles);
}

return roles;
}
}


}


EntityCollection<T> is just a wrapper around a plain IList which simply routes calls to IList methods (planning to possibly implement IBindingList so its usage could get more advantageous than just allowing generic access).

This seems to be a good solution for my needs, except of a problem with using NHibernateUtil.Initialize to initialize the collection in the business tier for use in the UI client tier, because that method does not use the
access="field.camelcase-underscore" mapping file provided access naming strategy for the collection association:


public static void Initialize( object proxy )
{
if( proxy == null )
{
return;
}
else if( proxy is INHibernateProxy )
{
NHibernateProxyHelper.GetLazyInitializer( ( INHibernateProxy ) proxy ).Initialize();
}
else if( proxy is PersistentCollection )
{
( ( PersistentCollection ) proxy ).ForceInitialization();
}
}


Am I wrong thinking that NHibernateUtil.Initialize should consider access strategy when accessing its "proxy" parameter?

Regards,

Bartol


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 5:38 am 
Newbie

Joined: Mon Jan 16, 2006 12:59 pm
Posts: 5
Location: Zagreb, Croatia
I've managed to copy-paste the wrong XML in my previous post:


<bag name="_roles" cascade="all-delete-orphan" access="field.camelcase-underscore"
lazy="true" inverse="true" >
<key column="ApplicationId" />


<one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogRoleEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
</bag>


should read:


<bag name="Roles" cascade="all-delete-orphan" access="field.camelcase-underscore"
lazy="true" inverse="true" >
<key column="ApplicationId" />


<one-to-many class="Bss.AppFramework.Common.Catalog.Admin.CatalogRoleEntity, Bss.AppFramework.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c38a8b11dd11713" />
</bag>


Note the different "name" attribute.


Sorry for this.

Regards,

Bartol


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.