Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# arnesten 5/25/2007 10:27 AM
Hi,

for those who are interested, I've created patches for Cuyahoga (both for 1.5.0 and current trunk) to make it work with NHibernate 1.2. The main advantages with NHibernate 1.2, in my opinion, is the support for generics.
Read more about it in my blog: http://www.arnesten.com/2007/05/25/using-nhibernate-12-with-cuyahoga/

I've also created a jira: http://jira.cuyahoga-project.org:8080/jira/browse/CUY-130

# martijnb 5/25/2007 10:43 AM
Thanks a lot.

Moving to NH 1.2 is already being worked on by Max, including upgrading the Castle stuff to the current trunk. I believe he didn't commit it yet.
# jmas 6/7/2007 11:29 AM
Hi,

I've noticed a Cuyahoga/NHibernate 1.2 patch for the trunk. Will this also work for the 1.5 release? Or is there going to be a separate patch for the 1.5 release?

THanks,
Joe
# martijnb 6/7/2007 2:09 PM (edited 6/7/2007 2:11 PM)
I expect that the patch in Jira will also work for 1.5.0 without many issues.

[edit]

Also found the patch for 1.5.0 on Calle Arnesten's weblog: http://www.arnesten.com/wordpress/wp-content/patch-cuyahoga-150-nhibernate-12.zip
# jmas 6/8/2007 12:20 PM
Thanks Martijn.
# jmas 12/28/2007 9:01 PM
Hi,

I am now considering migrating to the NH 1.2 patch option, for the Cuyahoga 1.5 release. My situation is the following:

In addition to our Cuyahoga Web Application, we have developed a backend Windows service that is built on the same Cuyahoga platform to support our Web Services. This Service is running all the time. Through normal MySQL behavior, the MySQL DB service will timeout/close our stale connections based on the configured timeout settings. Once our connections are closed by MySQL, our service app fails to re-connect.

After reading some of the NH 1.2 release notes, the following is mentioned about DB connections:

***************************************
Database connection release mode

In NHibernate 1.0 a session acquired a database connection when needed and then held onto to it until closed. As of 1.2, however, the session will release the connection after the database transaction completes. If you are not using NHibernate transactions, the session assumes it is in auto-commit mode, and will release the connection after every operation. The session will automatically re-acquire connection the next time it is needed.
***************************************

My questions are:

1) Is migrating to NH 1.2 the only way to free up connections after our transactions are complete?
2) Is there another/easier way to accomplish this in the current Cuyahoga (1.5, NH 1.0) version?
3) Is there a central place, either in Castle, NH or Cuyahoga to free connections or reconnect?


Thanks for your response,
Jmas

# martijnb 12/29/2007 12:21 PM
How are you managing the NH session in the service application right now? There is no HttpContext to store the session.

With Cuyahoga 1.5.0 there are already plenty options to use short-lived sessions. For example, when you are using the (old) CoreRepository, the way to use a short-lived session goes like this:
using (ISession session = coreRepository.ActiveSession)
{
    // Do stuf with session
}

The using block makes sure Dispose() is called on the session after each block.
# jmas 1/2/2008 5:05 AM
Hi Martijn,

I could be missing something, but I am not explicitly managing NH sessions. I assumed they were managed by using Castle.Facilities.NHibernateIntegration.ISessionManager. An example of our DAO method below makes use of Castle Transactions. Does this not Open a session, and then dispose the session when the theSessionObj object goes out of scope?

[Transaction(TransactionMode.Requires)]
public virtual void SaveOrUpdateEstimate(Domain.Estimate estObj)
{
ISession theSessionObj = this.m_sessionManager.OpenSession();
try {
theSessionObj.SaveOrUpdate(estObj);
}
catch (Exception ex) {
throw new ClException("JobManagementDao::SaveOrUpdateEstimate() Failed Transaction", ex);
}
}

With your help from a previous post --> http://www.cuyahoga-project.org/home/forum.aspx?g=posts&t=684, I successfully re-purposed our Cuyahoga web application into a new console/service application. All is working fine except the MySQl DB connections are never being closed. I assumed the ‘Session per request’ pattern was being taken care of by the Castle/NH infrastructure?

Please comment on my assumptions/questions:

1) Since a console application has no ASP.NET page lifecycle, is this the main reason why our sessions/connections are not being closed? My console application never terminates, therefore the connections/sessions never close properly?

2) Without changing any code in the Cuyahoga.Core.DataAccess.CommonDao, should the method below properly close sessions/connections if this code was included and compiled into a properly built console application? I would assume it would, maybe that is my confusion. Does it only behave that way in a Web app (because its tied to an ASP.NET page lifecycle)?

[Transaction(TransactionMode.Requires)]
public virtual void SaveOrUpdateObject(object obj)
{
ISession session = this._sessionManager.OpenSession();
session.SaveOrUpdate(obj);
}


Thanks again,
Jmas
# martijnb 1/2/2008 6:55 PM
jmasI could be missing something, but I am not explicitly managing NH sessions. I assumed they were managed by using Castle.Facilities.NHibernateIntegration.ISessionManager. An example of our DAO method below makes use of Castle Transactions. Does this not Open a session, and then dispose the session when the theSessionObj object goes out of scope?

[Transaction(TransactionMode.Requires)]
public virtual void SaveOrUpdateEstimate(Domain.Estimate estObj)
{
ISession theSessionObj = this.m_sessionManager.OpenSession();
try {
theSessionObj.SaveOrUpdate(estObj);
}
catch (Exception ex) {
throw new ClException("JobManagementDao::SaveOrUpdateEstimate() Failed Transaction", ex);
}
}

Ah, you're fully utilizing the Castle stuff. In that case, you have to configure facilities.config for the windows service app (set isWeb="false" in the facility declaration).
With your help from a previous post --> http://www.cuyahoga-project.org/home/forum.aspx?g=posts&t=684, I successfully re-purposed our Cuyahoga web application into a new console/service application. All is working fine except the MySQl DB connections are never being closed. I assumed the ‘Session per request’ pattern was being taken care of by the Castle/NH infrastructure?

That's true, and 'Session per request' is something that you don't want in a service/console app. Therefore you have to set isWeb to false (see above).
2) Without changing any code in the Cuyahoga.Core.DataAccess.CommonDao, should the method below properly close sessions/connections if this code was included and compiled into a properly built console application? I would assume it would, maybe that is my confusion. Does it only behave that way in a Web app (because its tied to an ASP.NET page lifecycle)?

[Transaction(TransactionMode.Requires)]
public virtual void SaveOrUpdateObject(object obj)
{
ISession session = this._sessionManager.OpenSession();
session.SaveOrUpdate(obj);
}

In theory, it's preferable to do this:
using ISession session = this._sessionManager.OpenSession()
{
    session.SaveOrUpdate(obj);
}

but there was an issue with this, because disposing the session (via the using construct) did close the session too early in the session per request scenario. It might have been solved in later Castle versions, but I'm not sure.

I think for a service app, the following scenario will do:
1. Service app needs to perform an action
2. Action is executed via a business component that manages the session and optionally, the transaction. When isWeb is set to false, the session is stored in the CallContext (by the NH facility) and available to other components that run in the same thread/context. Since there is no httpmodule that disposes the session after each request, it's important to manage the session manually.
3. Business component delegates DAO stuff to ICommonDao. No code change needed.

Hope this helps.
# delish 1/15/2008 3:52 AM
Had anyone done any work to move to using generics in the data access layer?
# mgaerber 1/23/2008 8:12 PM
Hi,

I guess Martijn is right about me having not committed my latest efforts towards NH 1.2 to the trunk but this mainly because of really annoying change of behaviour in conjunction with the castle container...

I'll check what I've got and what might be (still/again) usable.

Regards,

Max
# mgaerber 1/23/2008 9:04 PM (edited 1/23/2008 9:05 PM)
Nope - actually, the current trunk uses Castle 1.0.3.x and NH 1.2, all the Domain class mapping files are defined for NH 1.2 as well.

I just committed a fix for the current trunk because the decorator chain wouldn't work:
public ContentItemService(/*IContentItemDao<T> contentItemDao*/){
			this.contentItemDao = Util.IoC.Container.Resolve<IContentItemDao<T>>("core.searchdecorator");
        }

Right now, the outermost of the chained decorators needs to be called by its id - I don't know if this is still a problem with newer Castle builds but that is something I have to investigate...