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.