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.  [ 3 posts ] 
Author Message
 Post subject: Querying Detached Lazy Persistent Collection Lock()/Update()
PostPosted: Thu Feb 14, 2008 12:39 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
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.


Top
 Profile  
 
 Post subject: Applying criteria to associations
PostPosted: Thu Feb 14, 2008 1:22 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
Part of the answer is that I need to applying criteria to associations. This can be found in the documentation section 12.4.

Code:
IList cats = sess.CreateCriteria(typeof(Cat))
    .Add( Expression.Like("Name", "F%")
    .CreateCriteria("Kittens")
        .Add( Expression.Like("Name", "F%") )
    .List();


So if I lock the detached object to the ISession will it use that instance in the criteria query above?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 14, 2008 5:01 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 1:48 pm
Posts: 30
RESOLVED!

Code:

                IQuery query = session.CreateFilter(day.Visits, "where this.CallSequence = :callSq");
                query.SetInt32("callSq", 1);
                IList<Visit> visits = query.List<Visit>();


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