Inheritence issue with Hibernate

V

vj

Hi,

I am new to hibernate and was experimenting with inheritance when i
ran into this problem. Basically i have modelled an entity named as
Tag which has 2 major attributes. TagTitle and TagData. Now Tag is
subclassed by many classes like LocationTag, CommentTag , ImageTag
etc. They all use the TagData field to store their data.

I have a configured Tag.hbm.xml file where i have declared the
subclasses but left there property set empty since all of then wil be
using the parent class getters and setters. below is an excerpt from
the file.

<class name="Tag" table="usertags" >
<id name="TagID" column="tagid" type="long">
<generator class="native"/>
</id>
<discriminator column="tagtype" type="string"/>

<property name="TagData" column="tagdata" type="string"/>
<property name="TagTitle" column="tagtitle" type="string"/>

<subclass name="LocationTag" discriminator-
value="locationtag">
</subclass>


The LocationTag uses the tagdata field to store the longitude and
latitude info in comma separated format. Like 22.345,-23.445

Now i have implemented a method in LocationTag class to parse and
retrive the Longitude & Latitudes (getLongitude , getLatitude) from
the datafield. & corrosponding setMethods set the datafield in
appropriate format.

The issue is arising when i want to use the Hibernate Query Language
to query locations whose longitude is say 22.23. I wrote following
code.

Query qr= session.createQuery(" from LocationTag as tg where
tg.Longitude=22.23");
List<LocationTag> lst=qr.list();
for(LocationTag ltg:lst)
System.out.println(ltg.getLocationName());

I throws a Could not resolve property Longitute exception. So i am
unable to understand how describe a attriute which is infact derived
from another attribute.

If i am posting to a wrong groups please point me an appropriate
group.

Thanks,
 
R

Robert Klemme

Hi,

I am new to hibernate and was experimenting with inheritance when i
ran into this problem. Basically i have modelled an entity named as
Tag which has 2 major attributes. TagTitle and TagData. Now Tag is
subclassed by many classes like LocationTag, CommentTag , ImageTag
etc. They all use the TagData field to store their data.

I have a configured Tag.hbm.xml file where i have declared the
subclasses but left there property set empty since all of then wil be
using the parent class getters and setters. below is an excerpt from
the file.

<class name="Tag" table="usertags" >
<id name="TagID" column="tagid" type="long">
<generator class="native"/>
</id>
<discriminator column="tagtype" type="string"/>

<property name="TagData" column="tagdata" type="string"/>
<property name="TagTitle" column="tagtitle" type="string"/>

<subclass name="LocationTag" discriminator-
value="locationtag">
</subclass>


The LocationTag uses the tagdata field to store the longitude and
latitude info in comma separated format. Like 22.345,-23.445

Now i have implemented a method in LocationTag class to parse and
retrive the Longitude & Latitudes (getLongitude , getLatitude) from
the datafield. & corrosponding setMethods set the datafield in
appropriate format.

The issue is arising when i want to use the Hibernate Query Language
to query locations whose longitude is say 22.23. I wrote following
code.

Query qr= session.createQuery(" from LocationTag as tg where
tg.Longitude=22.23");
List<LocationTag> lst=qr.list();
for(LocationTag ltg:lst)
System.out.println(ltg.getLocationName());

I throws a Could not resolve property Longitute exception. So i am
unable to understand how describe a attriute which is infact derived
from another attribute.

If i am posting to a wrong groups please point me an appropriate
group.

Try to use "longitute" (lowercase first char) as property name in your
query.

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top