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.  [ 1 post ] 
Author Message
 Post subject: Dereference/cascade problem with Array
PostPosted: Fri Mar 02, 2007 4:45 pm 
Newbie

Joined: Tue Feb 20, 2007 12:04 pm
Posts: 16
I realize that there are plenty of posts that pertain to the deference/cascade issue with collections (answer: use Clear), however, I'm working strongly-typed arrays and can't seem to get around the problem of wanting to add items to the array without having to delete everything first.

For backgrounder, here's my mapping:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
  <class name="com.brightharbour.schema.MediaProviderType, BH.Service" table="Providers">
    <id name="ProviderId" column="ProviderId" type="String">
      <generator class="uuid.hex" />
    </id>
    <property name="ProviderType" type="String"/>
    <property name="ProviderUrl" type="String"/>
    <property name="LoginId" type="String"/>
    <property name="Password" type="String"/>
    <array name="Songs" table="Songs" cascade="all-delete-orphan">
      <key column="ProviderId"/>
      <!--Matching key in the child table that links to the parent-->
      <index column="SongIndex" />
      <!-- Column in child table used to hold the index (0-based) for the array-->
      <one-to-many class="com.brightharbour.schema.SongType, BH.Service"/>
    </array>  </class>
</hibernate-mapping>


...and here's where I'm having a problem:

Code:
ISessionFactory factory = cfg.BuildSessionFactory();
                ISession session = factory.OpenSession();
                ITransaction transaction = session.BeginTransaction();

                // Use Get to determine if the record already exists
                UserType user = (UserType)session.Get(typeof(UserType), userId);

MediaProviderType[] mediaProviders;

                    // Add a new Provider for the User
                    int len = user.Providers.Length;

                    Array.Clear(user.Providers, 0,len);
                    // Expand the array size by 1 to accommodate the new item
                    MediaProviderType[] temp = new MediaProviderType[len + 1];
                    mediaProviders.CopyTo(temp, 0);
                    user.Providers = temp;

                    user.Providers[len] = new MediaProviderType();
                    user.Providers[len].ProviderType = "Orb";
                    user.Providers[len].LoginId = providerLogin;
                    user.Providers[len].Password = providerPwd;

                    // Tell NHibernate to update this User

                    session.SaveOrUpdate(user);
                    // commit all of the changes to the DB and close the ISession
                    transaction.Commit();  //Blows up here
                    session.Close();


All I want to do here is add an item to the strongly-typed array and persist it back to the DB. I've read in the forums that you need to issue a Clear() first, (which I've tried), but this doesn't seem to help.

Any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.