Hi!

I've got two simple classes ClassA and ClassB mapped with table-per-
concrete-class strategy. IssueClass can contain a reference to ClassA
or to ClassB. Here is the mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="HqlIssue" namespace="HqlIssue">

        <class name="ClassA" table="TableA">
                <id name="Id" column="RowId" type="Guid" >
                        <generator class="assigned" />
                </id>
        </class>

        <class name="ClassB" table="TableB">
                <id name="Id" column="RowId" type="Guid" >
                        <generator class="assigned" />
                </id>
        </class>

        <class name="IssueClass" table="Issue">
                <id name="Id" column="RowId" type="Guid" >
                        <generator class="assigned" />
                </id>

                <any name="Association" access="property"
                        id-type="Guid"
                        meta-type="String">
                        <meta-value value="A" class="ClassA"/>
                        <meta-value value="B" class="ClassB"/>
                        <column name="TypeId" />
                        <column name="EntityId" />
                </any>
        </class>

</hibernate-mapping>

When I'm trying to execute an HQL query with filter on property
"Association", I'm getting an error described here
http://groups.google.com/group/nhusers/browse_thread/thread/17122049e8207ac8
If I fix this bug in sources of NH, I'll get a more interesting error.
It seems, than NH does not expand property Association to two table
columns correctly and could not extract entity type and entity id from
parameter.

Here is the query: "delete from " + typeof(IssueClass).Name + " where
Association = ?"

Questions:
1. Does NHibernate support polymorphic HQL query of that kind?
2. Does NHibernate support polymorphic HQL query of that kind if I use
custom meta-type in <any> mapping?
3. If NH doesn't support this feature then is there any workaround?

I really need to execute queries with such polymorphic relations
(actually update's, not only delete's).

Query text and actual test case are following:
-----------------------------------------------------------------------
[TestFixture]
public class TestCase
{
        private Configuration configuration;
        private ISessionFactory sessionFactory;
        private ISession currentSession;

        [SetUp]
        public void SetUp()
        {
                configuration = new Configuration();
                sessionFactory = 
configuration.Configure().BuildSessionFactory();

                CreateDataScheme();

                currentSession = sessionFactory.OpenSession();
        }

        [TearDown]
        public void TearDown()
        {
                if (currentSession != null)
                {
                        currentSession.Dispose();
                        currentSession = null;
                }
        }

        [Test]
        public void HqlTest()
        {
                ClassA a = new ClassA();
                ClassB b = new ClassB();

                currentSession.Save(a);
                currentSession.Save(b);

                IssueClass c1 = new IssueClass();
                c1.Association = a;
                currentSession.Save(c1);

                IssueClass c2 = new IssueClass();
                c2.Association = b;
                currentSession.Save(c2);

                currentSession.Flush();

                currentSession = sessionFactory.OpenSession();

                string queryString = "delete from " + typeof(IssueClass).Name + 
"
where Association = ?";
                IQuery query = currentSession.CreateQuery(queryString);
                query.SetEntity(0, a);

                Assert.AreEqual(1, query.ExecuteUpdate());
        }

        public void CreateDataScheme()
        {
                var export = new SchemaExport(configuration);
                export.Create(false, true);
        }
}
----------------------------------------------------------------------

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to