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.  [ 1 post ] 
Author Message
 Post subject: HQL: max function doesn't work for strings
PostPosted: Thu Mar 11, 2010 4:40 pm 
Newbie

Joined: Mon Jan 25, 2010 12:06 am
Posts: 2
Hi!

First of all, sorry for my poor english.

Here's the problem:

I have an interface called IPersistentObject and a class called ChangeLogMessage, that implements it.
Here how I map them to MS SQL Server 2005:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="PersistentData" namespace="PersistentData">
  <class name="IPersistentObject" table="TBL_PERSISTENT_OBJECTS" abstract="true">
    <id name="id" type="string" length="18">
      <column name="ID"/>
      <generator class="PersistentData.PrefixIDGenerator, PersistentData"/>
    </id>
    <discriminator column="discr" type="string"/>
  </class>
</hibernate-mapping>


and

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MedicalData" namespace="MedicalData.Logging">
  <subclass name="ChangeLogMessage" extends="PersistentData.IPersistentObject" discriminator-value="ChangeLogMessage">
    <join table="TBL_CHANGE_LOG">
      <key foreign-key="FK_CHANGE_LOG_MESSAGE" column="ID"/>
      <property name="objectID" column="objectID" not-null="true"/>
      <property name="type" column="type" type="ChangeType" not-null="true"/>
    </join>
  </subclass>
</hibernate-mapping>


I use here clean just created database. So all the tables are empty.

What I want, is to find maximum id of particular class.
I use the following HQL for that:
Code:
select max(obj.id)
from #class-name# as obj

Of course I put PersistentData.IPersistentObject or MedicalData.Logging.ChangeLogMessage instead of #class-name#.

For IPersistentObject class it works perfectly. But as for ChangeLogMessage, SQLServer just hangs (or how is it called on english, when something reacts on nothing?). It becomes alive only after restart.

The SQL passed to SQLServer is following (according to logs):
Code:
select max(changelogm0_.ID) as col_0_0_
from TBL_PERSISTENT_OBJECTS changelogm0_
   inner join TBL_CHANGE_LOG changelogm0_1_ on changelogm0_.ID=changelogm0_1_.ID
where changelogm0_.discr='ChangeLogMessage'


Does anybody know what's going on?

P.S. When running the above SQL directly in SQL Server Management Studio, it works fine and returns null.

P.P.S. Just noticed, that it doesn't work for count function too.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.