-->
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: Compilation seems to be looping
PostPosted: Sun May 27, 2007 6:48 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I am experiencing a strange problem where the ASP.NET compiler seems to be looping when I try to use the NH session to get a domain object in the constructor of another domain object.

The page never loads and I can see multiple csc.exe processes get started and eventually the VS 2005 development web server crashes. It seems to be happening in the NH initialisation that normally occurs when you first fire up an application in debug.

I am wondering if NH instantiates each domain object during initialisation which results in a never ending loop of some kind because my constructor tries to load an object from the session which has not yet been initialised.

Should I be able to load an object in the constructor of another object or is this a big no-no!? I need to be able to initialise the Status property of my object when it is first created...is there another way to achieve this?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 2:21 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate instantiates an object of your class to find out the default value of its identifier which it then uses as unsaved-value. csc.exe may also be run by the reflection optimizer of NHibernate (if you're using NH 1.0.x or .NET 1.1).

I wouldn't do anything that requires access to the session in the constructor since the object may be constructed by NHibernate itself when the session is doing something and is not reentrant.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 2:32 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Cool...thanks for the response Sergey.

I figured that NH must have been doing something like that and have moved the status initialisation out of the constructor.

What is the best practice for implementing the initialisation of properties on a domain object where those properties reference other domain objects?

In my case the Status property should have an initial value of "Created" and then there are other methods that can trigger an update of the Status. I have moved the initial assignment of "Created" into my service layer but it feels like it should really be in the domain somewhere.

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 3:13 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I don't understand why you need to access a session to assign the status? Why don't you just create a new Status object, or get it from a factory or whatever?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 3:25 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
We have a Status object with the following properties:

ID
Description

We effectively have 12 pre-defined statuses that exist in the database and we just want to load one of them and assign it to the new domain object we are creating (many-to-one).

That is why I was using the Session to retrieve it in the constructor.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 3:44 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can load the Status instance from the database at the beginning of your application, store it in some global variable, and have the domain object use that global one when it's created.


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.