-->
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.  [ 11 posts ] 
Author Message
 Post subject: Strange behaviour in RC1
PostPosted: Thu Sep 22, 2005 2:49 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
First of all i want to say something about RC1: WOW! The batch-loading alone has accelerated most of the queries. It is impressive how far NH has come since the 0.5 alpha I started using a few months ago.

I also wanted to report that I'm experiencing a strange behavior. I'm doing nothing new, just pluged in the new version.

What I'm getting is a "You cannot dereference a collection with cascade="all-delete-orphan" exception. I'm not sure what I'm doing wrong because log4net has stoped working misteriosly.

Thnaks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 3:15 pm 
Newbie

Joined: Sun Sep 18, 2005 3:44 pm
Posts: 9
Since I got RC1 log4net does no longer work for me either.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 3:44 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate no longer configures log4net itself, that's why logging doesn't work (it's stated in the release notes, by the way). As to why you are getting that error, I would need to see code and mappings to know. The exception is supposed to be thrown when you move a collection that is mapped with cascade "all-delete-orphan" to another object.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 9:29 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
About log4net: I have always configured it using web.config. I'm not sure what else am I suppose to configure in order to NH read the config.

Regarding the all-delete-orphan related I'm not sure what is happening. What I did is create a copy of an object setting all the new entities with the unsaved value. Here is the query:

Code:
select count(*) from Cartera c WHERE c.mFecha = :fecha and c.mTipo = :tipo and c.mAfjp= :afjp"


Here are the short versions of the mapping files:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

    <class
   name="Cartera"
        table="T_Cartera"
        batch-size="15">
       
        <id
      name="mId"
      column="cartera_ID"
      type="Int32"
      unsaved-value="-1">
      <generator class="native" />
   </id>
      
   <bag
      name="mStocks"
      table="T_Stock_Cartera"
      cascade="all-delete-orphan"
      lazy="true" >
           <key column="cartera_ID" />
      <one-to-many class="SAFJP.SICI.Model.Carteras.Stock" />
   </bag>
   
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">

    <class
   name="Stock"
        table="T_Stock_Cartera">
       
        <id
      name="mId"
      column="stockCartera_ID"
      type="Int32"
      unsaved-value="-1">
      <generator class="native" />
   </id>
      
   <bag
      name="mEntradasStock"
      lazy="true"
      cascade="all-delete-orphan">
      <key column="stockCartera_ID"/>
      <one-to-many class="IEntradaStock" />
   </bag>
      
   </class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="property">

    <class
   name="IEntradaStock"
        table="T_Entrada_Stock">
       
        <id
      name="Id"
      column="entradaStock_ID"
      type="Int32"
      unsaved-value="-1">
      <generator class="native" />
   </id>
      
   <discriminator
      column="tipoEntrada_Class"
      type="string"
      length="4"
   />
      
   <!-- ==================================  -->
   <!-- Subclass EntradaStock              -->
   <!-- ==================================  -->
   <subclass
      name="EntradaStock"
      discriminator-value="EMOV">
         
   </subclass>
      
   <!-- ==================================  -->
   <!-- Subclass EntradaStockAjuste        -->
   <!-- ==================================  -->
   <subclass
      name="EntradaStockAjuste"
      discriminator-value="EAJU">
         
      <property
         name="mDescripcion"
         column="X_motivoAjuste"
         type="String"
         access="field"
      />
         
   </subclass>

   </class>
   
</hibernate-mapping>


The code for making the copies is fairly simple (sorry for the VB.Net ; client requirement :? ). Each new sets the entitie's id to -1.

Code:
    Public Function CrearCopia(ByVal fecha As DateTime) As Cartera
        Dim cartera As New cartera(Me.Tipo, fecha, Me.Afjp)
        cartera.Descripcion = Me.Descripcion

        For Each st As Stock In Me.Stocks
            Dim newStock As Stock
            newStock = New Stock(st.FechaAlta)
            newStock.Precio = st.Precio
            cartera.Stocks.Add(newStock)
        Next

        Return cartera
    End Function


Please help!!

[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 9:48 am 
Beginner
Beginner

Joined: Thu May 12, 2005 3:41 am
Posts: 24
Location: London, UK
The simplest way to configure log4net is to make the following call:
Code:
log4net.Config.XmlConfigurator.Configure();

This needs to be before any calls to NHibernate and before any other calls to log4net in your application.
See http://logging.apache.org/log4net/ for more info.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 10:22 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Thanks...I got it work about 5' after I posted, but I more intrested in the other issue.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 11:26 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Last post was unclear. I got log4net to work, but the all-delete-orpahn issue is still without a fix


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 12:44 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Can you also post the actual code that exhibits a problem? What I have in mind is some kind of excerpt starting with factory.OpenSession() and ending with session.Close(). Also the exact error you are getting (along with a stack trace if possible) would be nice.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 11:04 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
After some extensive debugging (including NH source) :wink: we found the source of our problem.

We're not sure if it something we did wrong and the previous versions let us get away with it or it was due to a bug.

The problem came from the following mapping:


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
   xmlns="urn:nhibernate-mapping-2.0" 
   namespace="SAFJP.SICI.Model.Carteras"
   assembly="SAFJP.SICI.Model.Carteras"
   default-access="field">
   
    <class
      name="Recepcion"
      table="T_Recepcion">
           
      <id
         name="mId"
         column="recepcion_ID"
         type="Int32"
         unsaved-value="-1">
         <generator class="native" />
      </id>
      
      <property
         name="Dia"
         column="D_recepcion"
         type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"
         access="property"
         not-null="true"         
      />
      
   
      <component
         name="mFuentesYUsos"
         class="FuentesYUsos">
         <component
            name ="mCuentas"
            class="ICuentaCollection" >
            <bag
               name="mInternalCuentas"
               table="T_Cuenta_Fuentes_Y_Usos"
               order-by="Cuenta_ID"
               cascade="all-delete-orphan"
               lazy="true">
               <key column="Recepcion_ID" />
               <many-to-many column="Cuenta_ID" class="ICuenta"/>
            </bag>
         </component>
      </component>
      
   </class>
   
</hibernate-mapping>


ICuentaCollection is just a collection wrapper for ICuenta which is another mapped class.

The source for the bug was that we were setting the mFuentesYUsos to nothing as following:

Code:
recepcion.FuentesYUsos = nothing


and was replaced for

Code:
recepcion.FuentesYUsos.Cuentas.Clear()


NHibernate seems to be using the DELETE statement fine. Was puzzels me is how the code worked with previous versions and if this is a known enhanced enforcement. If so, could someone please explain it a bit better so that I we can check our code looking for such errors.

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 12:49 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
There were some updates to the relevant code to bring it up to H2.1, that's when the stricter checks got in. Now, why is the check needed in the first place? I'm not 100% sure, my understanding is as follows.

To implement cascade="all-delete-orphan" you need to know the current (or last) collection owner, and for unreferenced collections it's impossible to know the owner reliably - you can do something like this:
Code:
// Load ownerA with ownerA.Collection mapped as all-delete-orphan
ownerB.Collection = ownerA.Collection;
ownerB.Collection = null;
session.Flush();

Now NHibernate will think that the last owner of the collection was ownerA, while the user intended the last owner to be ownerB. The check is just to prevent this situation.

The only thing that I can't understand myself in my explanation is why we actually need the owner :) The collection is one-to-many, that means that its items can be identified individually and the owner is not needed to delete them. Maybe in some obscure situations changing the owner will mean changing the table to which the collection is persisted... or maybe Hibernate developers just wanted the code to be 101% fool-proof :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 2:39 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
Thanks sergey.

Unfortunately we kept bumping into that exception a couple of times after my last post and we're 2 days from a Demo. I'll be rolling back to 0.9.1 for now and come back to the latest release in a couple of days to see what we were doing wrong and maybe be able to report something more useful.


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