-->
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: NHibernate adding the same row twice
PostPosted: Sun Aug 15, 2010 1:37 am 
Newbie

Joined: Sun Aug 15, 2010 1:35 am
Posts: 2
The query (in the code), while running on SQL server returns the following result.

Code:
53      10      _heading        Supplier Sustainability Assessment      101     
53      10      _heading        FR_SUST 102     
54      10      _tabHome        Home    101     
55      10      _tabQuestionnaire       Questionnaire   101     
56      10      _tabResults     Results 101     
57      10      _tabResourcesFAQ        Resources & FAQs        101 


But while running the code on visual studio returns the first row twice and instead of the second row -

Code:
53      10      _heading        Supplier Sustainability Assessment      101     
53      10      _heading        Supplier Sustainability Assessment      101     
54      10      _tabHome        Home    101     
55      10      _tabQuestionnaire       Questionnaire   101     
56      10      _tabResults     Results 101     
57      10      _tabResourcesFAQ        Resources & FAQs        101   


I have no idea as to why.

Code.

Code:
private IList<WebpageElement> GetWBById(int id)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            using (ITransaction transaction = session.BeginTransaction())
            {
                try
                {
                    string sql = @"
                                                SELECT     
                        web_page_html_element.html_element_id,
                        web_page_html_element.web_page_id,
                        html_element.html_element_name,
                        Html_Element_Text.html_element_txt,
                        Html_Element_Text.language_code
                        FROM  Web_Page_Html_Element INNER JOIN
                        Html_Element ON
                        Web_Page_Html_Element.html_element_id = Html_Element.html_element_id INNER JOIN
                        Html_Element_Text ON Html_Element.html_element_id = Html_Element_Text.html_element_id
                        WHERE (Web_Page_Html_Element.web_page_id = :id)";

                    ISQLQuery query = (ISQLQuery)session.CreateSQLQuery(sql)
                        .SetInt32("id", id);
                    var list = query.AddEntity(typeof(WebpageElement)).List<WebpageElement>();
                    return list;
                }
                finally
                {
                    transaction.Commit();
                }
            }

        }

WebpageElement.CS
Code:
        public class WebpageElement
        {
                public virtual int Id { get; set; }
                public virtual int WebpageId { get; set; }
                public virtual string Name { get; set; }
                public virtual string Text { get; set; }
                public virtual string LanguageCode { get; set; }

                public WebpageElement() { }
        }

WebpagElement.hbm.xml
Code:
        <class name="WebpageElement" table="web_page_html_element">
                <id name="Id" column="html_element_id">
                        <generator class="native"/>
                </id>
                <property name ="WebpageId">
                        <column name="web_page_id"></column>
                </property>
                <join table="html_element">
                        <key column="html_element_id" />
                        <property name="Name">
                                <column name="html_element_name" />
                        </property>
                </join>
                <join table="html_element_text">
                        <key column="html_element_id"/>
                        <property name="Text">
                                <column name="html_element_txt" />
                        </property>
                        <property name="LanguageCode">
                                <column name="language_code" />
                        </property>
                </join>
        </class>


Top
 Profile  
 
 Post subject: Re: NHibernate adding the same row twice
PostPosted: Mon Aug 16, 2010 4:28 pm 
Newbie

Joined: Sun Aug 15, 2010 1:35 am
Posts: 2
Bump. Anybody?!


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.