This is a migrated thread and some comments may be shown as answers.

[Solved] About IInitializeTransients

4 Answers 126 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrey
Top achievements
Rank 1
Andrey asked on 15 Mar 2011, 10:01 PM

Hello, Telerik team!

I have an entity with some [Transient] fields. And my Entity realizes interface IInitializeTransient.

And I have some logic for initialize these fields. But this Initialize() method is in other class and in other dll. And it is called in some EntityManager, because initialize logic for some [Transient] fields is difficult. And it is large source code block with many dependencies. And Entity shouldn't know about all of this.

And of course my entity doesn't know anything about this Initialize() logic.

So, I have a problem when I Flush() my entity - all [Transient] fields are Reset. How I can not Reset [Transient] fields and use them after Flush() without duplicate call difficult Initialize() logic?

Thanks!

4 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 15 Mar 2011, 10:45 PM
Hello Andrey,
We are not touching the transient fields at all. If they are reseted you have a new instance. IInitializeTransients is called too often, we know that. Can you switch to IInstanceCallbacks, that is not as flexible but easier to handle.

Best wishes,
Jan Blessenohl
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Anatol
Top achievements
Rank 1
answered on 16 Mar 2011, 01:58 PM
Hello, Telerik team!

In the same situation as Andrey, I have a code:
    
private readonly ITransaction tx;
     
    public void Flush(bool isStartNewTx = false)
    {
        try
        {
            if (tx.IsActive)
            {
                tx.Commit();
 
                if (isStartNewTx)
                {
                    tx.Begin();
                }
            }
        }
         catch (Exception)
        {
            if (tx.IsActive)
            {
                tx.Rollback();
            }
 
            throw;
        }
         finally
        {
            if (!isStartNewTx)
            {
                scope.Dispose();
            }
        }
    }
InitializeTransients() call occurs after commiting transaction when tx.Begin() is calling. In the beginning of InitializeTransients() method Transient fields are Reset, so it does not make sense to check initOperation parameter.
Is it normal behavior of IInitializeTransients (reseting transiet fields in any case) or I can make some configurations for it to avoid Reset?
Using IInstanceCallbacks.PostLoad() instead InitializeTransients() has no positive effect.

Thanks!
0
Andrey
Top achievements
Rank 1
answered on 16 Mar 2011, 07:34 PM

I change my entity to IInstanceCallbacks. But still have my problem.

As Anatol said, I call

transaction.Commit();

And then automatically is called

PostLoad();

And in this method I have all RESETED [Transient] fields already.

Why???

I don't need Reinitialize Initialized fields. Why is it called??

I want only to Commit() my object to DB and then proceed to work with this object in my application.

I don't need ReLoad and ReInitialize my object.

How I can solve my problem? 

Thanks!

0
Jan Blessenohl
Telerik team
answered on 18 Mar 2011, 05:24 PM
Hello Andrey,
PostLoad is called after the fields in the object are loaded from the database. If you call commit followed by begin, all objects are marked as 'Hollow' which means if you access a field the next time, fresh data is loaded from the database. Because the data in your object might be changed, like from another client, PostLoad is called again. Imaging that in PostLoad you want to calculate transient data that is based on persistent data, this has usually to be redone if you get new data from the database. For the one time initialization you might want to switch to the default constructor.

Kind regards,
Jan Blessenohl
the Telerik team
Tags
General Discussions
Asked by
Andrey
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Anatol
Top achievements
Rank 1
Andrey
Top achievements
Rank 1
Share this question
or