-->
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.  [ 8 posts ] 
Author Message
 Post subject: AVG, MIN in Nhibernate under .NET 2.0 don't work!
PostPosted: Sat Oct 22, 2005 10:31 am 
It seems that aggregation is not work under .NET 2.0. Can you confirm that you know about this bug?


Top
  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 3:46 am 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
I have the same issue. Can anybody help us to resolve it?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 7:44 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Please post details.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 3:29 pm 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
sergey wrote:
Please post details.


Thanks for reply.

Please find the details below:

This is nhibernate file (for Project class):

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="MySample.BusinessObjects.Project, MySample.BusinessObjects" table="Project">
      <id name="ProjectID" type="Int32" unsaved-value="0">
         <column name="ProjectID" sql-type="int" not-null="true" unique="true" index="PK_Project"/>
         <generator class="native" />
      </id>
      <property name="Name" type="String">
         <column name="Name" length="255" sql-type="varchar" not-null="false"/>
      </property>
      <property name="Description" type="String">
         <column name="Description" length="2147483647" sql-type="text" not-null="false"/>
      </property>
      <property name="StartDate" type="DateTime">
         <column name="StartDate" sql-type="datetime" not-null="false"/>
      </property>
      <property name="EndDate" type="DateTime">
         <column name="EndDate" sql-type="datetime" not-null="false"/>
      </property>
      <property name="Effort" type="Decimal">
         <column name="Effort" sql-type="decimal" not-null="false"/>
      </property>
   </class>
</hibernate-mapping>


This is method for retrieving integer value (It is NHibernate wrapper - Portal):

Code:
   
        public int RetrieveInt(string queryString)
        {
            IList list = m_Session.Find(queryString);
            return (int)list[0];
        }


This is a test method:

Code:
        [TestMethod]
        public void Min()
        {
            Project project = Project.Create();

            project.Name = "This is name";
            project.Description = "This is description";
            project.Effort = 10;
            project.StartDate = DateTime.Now;
            project.EndDate = DateTime.Now.AddMonths(1);
            portal.Save(project);

            Project projectDouble = Project.Create();

            projectDouble.Name = "This is name 2";
            projectDouble.Description = "This is description 2";
            projectDouble.Effort = 15;
            projectDouble.StartDate = DateTime.Now;
            projectDouble.EndDate = DateTime.Now.AddMonths(1);
            Project.Save(projectDouble);

            Assert.AreEqual(project.ProjectID, Portal.Instance.RetrieveInt("select min(Project.ProjectId) from Project"));
        }



The method above gives the following exception:
Code:
Test method MySample.BusinessObjects.Test.ModelTest.Min threw exception:  System.InvalidCastException: Specified cast is not valid.


The debug shows that the following line

Code:
            IList list = m_Session.Find(queryString);


of RetrieveInt code gives the list of 2 elements, in other words the
Code:
m_Session.Find("select min(Project.ProjectId) from Project")
returns the list of all project's entities in database's table [Project].

And also one more question using the moment. When do you plan to full support .NET 2.0 (if you plan it :D )?

Looking forward to hearing from you.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 4:43 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I think .NET 2 is not to blame here (or does this same code work on .NET1.1?), try rewriting your query as "select min(p.ProjectID) from Project as p".

As for .NET 2.0 support, I haven't yet thought much about it. It would require some work on the build files, to be able to build both .NET1.1 and .NET2.0 versions at once. I will look into it some time after the final version of .NET2.0 comes out.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 5:08 pm 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
sergey wrote:
I think .NET 2 is not to blame here (or does this same code work on .NET1.1?), try rewriting your query as "select min(p.ProjectID) from Project as p".

As for .NET 2.0 support, I haven't yet thought much about it. It would require some work on the build files, to be able to build both .NET1.1 and .NET2.0 versions at once. I will look into it some time after the final version of .NET2.0 comes out.


Thanks very much. Your query works succeffully. By the way I coded my query as "select min(p.ProjectID) from p in class Project" (I take it from NHibernate tests), but it seems that it doesn't work as well.
So I always should create the alias "[Table] as [alias]" for using queries. Thanks for this information.

Thanks for answer related to .NET 2.0 support. It is clear.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 5:33 pm 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
sergey wrote:
I think .NET 2 is not to blame here (or does this same code work on .NET1.1?), try rewriting your query as "select min(p.ProjectID) from Project as p".

As for .NET 2.0 support, I haven't yet thought much about it. It would require some work on the build files, to be able to build both .NET1.1 and .NET2.0 versions at once. I will look into it some time after the final version of .NET2.0 comes out.


Sorry... I have one more question. Does the aggregation work for Inherited classes as well.

For example for the following hbm:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="MySample.BusinessObjects.Assignable, <MySample.BusinessObjects" table="Assignable">
      <id name="AssignableID" type="Int32" unsaved-value="0">
         <column name="AssignableID" sql-type="int" not-null="true" unique="true" index="PK_Assignable"/>
         <generator class="increment" />
      </id>
      <property name="Name" type="String">
         <column name="Name" length="255" sql-type="varchar" not-null="false"/>
      </property>
      
      <joined-subclass name="MySample.BusinessObjects.TimeEntity, MySample.BusinessObjects" table="TimeEntity">
         <key column="TimeEntityID"/>
         <property name="SuperTime" type="DateTime">
            <column name="SuperTime" sql-type="datetime" not-null="false"/>
         </property>
      </joined-subclass>
   </class>
</hibernate-mapping>


The query:

"select min(te.TimeEntityID) from TimeEntity as te" should work as well, is it right assumption?

I just wrote a test method for case above and it seems that I have the problem for inherted entities:

This is a test method:

Code:
   [TestMethod]
        public void Inherintance()
        {
            TimeEntity timeEntity = TimeEntity.Create();
            timeEntity.Name = "Super Test";
            timeEntity.SuperTime = DateTime.Now;
            TimeEntity.Save(timeEntity);
           
            Portal.Instance.Reconnect();

            TimeEntityCollection collection = new TimeEntityCollection(Portal.Instance.Retrieve("from TimeEntity te where te.Name = 'Super Test'"));
            Assert.AreEqual(1, collection.Count);
            collection = new TimeEntityCollection(Portal.Instance.Retrieve("from TimeEntity te where te.Name = 'Super Test 1'"));
            Assert.AreEqual(0, collection.Count);

            timeEntity = TimeEntity.Create();
            timeEntity.Name = "Super Test 2";
            timeEntity.SuperTime = DateTime.Now;
            TimeEntity.Save(timeEntity);

            Portal.Instance.Reconnect();

            collection = new TimeEntityCollection(Portal.Instance.Retrieve("from TimeEntity"));
            Assert.AreEqual(2, collection.Count);

            Assert.AreEqual(1, Portal.Instance.RetrieveInt("select min(te.TimeEntityID) from TimeEntity as te"));
        }


the last assert gives the exception System.InvalidCastException: Specified cast is not valid..

I really appreciate your help. Thanks for your time.

Looking forward to hearing from you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 2:04 pm 
Newbie

Joined: Sun Oct 23, 2005 3:42 am
Posts: 7
Location: Minsk, Belarus
Oleg wrote:
sergey wrote:
Assert.AreEqual(1, Portal.Instance.RetrieveInt("select min(te.TimeEntityID) from TimeEntity as te"));
}[/code]

the last assert gives the exception System.InvalidCastException: Specified cast is not valid..



The issue was resolved. I should not use TimeEntityID for quieries. In other words NH doesn't see this field. I shoudl use AssignableID instead of TimeEntityID.

Sorry for distrubing.

Spasibo za vnimanie.


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