-->
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.  [ 3 posts ] 
Author Message
 Post subject: Polymorphic queries
PostPosted: Tue Jun 14, 2005 3:08 am 
Hi all!

I have a map:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Picture"
table="tb_picture">
<id name="id" column="id" type="Int64" unsaved-value="0"> <generator class="identity" />
</id>
<discriminator column="dsc"></discriminator>
<property name="caption" column="caption" type="String(50)"/>
<property name="idGoods" column="id_goods" type="Int64"/>
<many-to-one name="type"
class="PictureType"
column="id_picture_type"/>

<subclass name="PictureData, Core" discriminator-value="1">
<property name="data" column="data" type="BinaryBlob"></property>
</subclass>

</class>
</hibernate-mapping>

and when I make the following query:
FROM Picture picture WHERE picture.idGoods = :idGoods

it returns objects of PictureData class but I need objects of Picture class

How can I get this result?

Thanks.


Top
  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 3:28 pm 
Newbie

Joined: Wed Jun 15, 2005 9:22 am
Posts: 1
Does your query return just PictureData objects or all objects?

I had a similar query that was returning all objects:
(pardon my vb)
Code:
    Public Function GetAllInputSets() As IList
        '
        Dim hql As String = "from InputSet"
        Return Me._nhSession.Find(hql)
        '
    End Function

After adding " where dsc='x'" to the hql, the list was narrowed down correctly. Maybe someone else knows the correct technique?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 12:14 am 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
I really don't see where the problem is, since PictureDate object ARE Picture object...

Besides, nhibernate should be returning a collection of Picture and PictureData objects depending on the discriminator value. The whole point of inheritance is that you can use both as if they where Picture objects.


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