-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to make the session recognize my object
PostPosted: Mon Jul 27, 2009 3:47 pm 
Newbie

Joined: Mon Jul 27, 2009 3:34 pm
Posts: 3
Hello all, after creating a sample web application POC using the Entity Framework I am attempting to do the same with NH. I ran into what is probably a very simple issue however I can't quite find the solution. My web application is passing an Author object to my service which then supposed to delete the author and all of its children (Articles). I am not utilizing cascading delete so I am trying to nuke those articles manually before I nuke the author, however I can't get the author.Articles list to populate. In the below example author.Articles is always null. I understand I must be missing something regarding the disconnected nature of what I am attempting to do here, but in Entity Framework I was able to simply attach my entity to the ObjectContext (session in NH) and go from there as usual. I recognize that I could simply query first for the Author instance first, but the whole point is to avoid that query as I already have that object being passed into the service.
Thanks!

Code:
public void DeleteAuthor(Author author)
        {
            using (ISession session = GetSession())
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    try
                    {
                        foreach (Article article in author.Articles)
                        {
                            session.Delete(article);
                        }

                        session.Delete(author);
                        session.Flush();
                        tx.Commit();
                    }
                    catch (HibernateException)
                    {
                        tx.Rollback();
                        throw;
                    }
                }
            }
        }


Top
 Profile  
 
 Post subject: Re: How to make the session recognize my object
PostPosted: Tue Jul 28, 2009 3:02 pm 
Newbie

Joined: Mon Jul 27, 2009 3:34 pm
Posts: 3
So after digging around more I now understand that the issue is that when my object is passed from the disconnected layer back to the service it doesn't contain the proxy class for author.Articles. Is there any way around this without having to reselect the author object on the way back from the disconnected layer.


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