Hibernate version: 1.2.1 GA
Name and version of the database you are using: MS SQL 2000
.Net 2.0 Web Project
Okay, I have read the “How to Ask for Help”, Documents/API and several articles and examples on the web however I can not resolve this, yet! I hope I’m not insulting if the question is simple and I hope I have the opportunity to repay the community by answering others questions.
I have NHibernate up and running with log4net. I create one session factory (Application Scope) and one session per HttpRequest. I have some domain objects with mappings and can pull data from the db as follows:
Code:
IQuery query = session.CreateQuery("select d from Day as d where d.ID = :dayId");
query.SetInt32("dayId", 7485);
IEnumerable days = query.Enumerable();
Then this Day instance gets stored in the Session for use in future requests (I need to do more research on second-level cache). In a following request I lock the detached object with the new ISession - session.Lock(day, LockMode.None);//assuming no updates
Day has the following association map:
Code:
<set name="Visits" table="Visit" access="nosetter.camelcase-underscore" lazy="true">
<key column="DayID"/>
<one-to-many class="Visit"/>
</set>
Here is want I need to accomplish. The user has entered some criteria to filter visits on. So for the given day in .Net Session memory I want to filter the visits collection based on the criteria. I would like to use IQuery or ICriteria, Filter() is deprecated. How do I referance the newly locked object in the HQL? Here is what I have tried:
Code:
session.Lock(day, LockMode.None);
IQuery query = session.CreateQuery("from Day.Visits as visit where visit.Name = :name");
query.SetInt32("name", name);
IEnumerable visits = query.Enumerable();
I’m sure this is a common task that I’m just not familiar with in the NHibernate world. Thanks in advance.