-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL "FROM BaseClass" doesn't work for implicit pol
PostPosted: Mon May 28, 2007 11:30 am 
Beginner
Beginner

Joined: Tue Aug 23, 2005 8:15 am
Posts: 45
Doesn't work:
IQuery query = project.Session.CreateQuery("FROM BaseClass");
query.List();

Work:
ICriteria crit = project.Session.CreateCriteria(typeof(BaseClass));
crit.List();

WHY?

Table-per-concrete class (implicit polymorphism) is used for
inheritance mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 11:41 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You have an error on line 33 of your application!

Seriously, it should work but how can we know why it doesn't? Give us details.


Top
 Profile  
 
 Post subject: Some details
PostPosted: Mon May 28, 2007 5:26 pm 
Beginner
Beginner

Joined: Tue Aug 23, 2005 8:15 am
Posts: 45
Fragment from domain classes:

Code:
namespace IDS.Domain
{
    // base class
    public class EventFact
    {
        public DateTime Time;
    }

    // one of parent classes
    public class TrafficFact : EventFact
    {
        public Int32 Id;
        public Process Process;
        public LocalPort LocalPort;
        public RemotePort RemotePort;
        public RemoteAddress RemoteAddress;
        public Int32 BytesSent;
        public Int32 BytesReceived;
        public ProtocolType ProtocolType;
        public Computer Computer;
        public User User;
    }

}


Part of mappings:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="IDS.Domain" assembly="IDSDomain">
   <class lazy="false" mutable="false" name="TrafficFact" table="Traffic_Facts">
      <id access="field" name="Id" column="idFact" unsaved-value="0">
         <generator class="identity" />
      </id>
      <property access="field" name="Time" column="tmTransfer" not-null="true"/>
      <many-to-one access="field" class="Process" name="Process" column="idProcess" not-null="true"/>
      <many-to-one access="field" class="LocalPort" name="LocalPort" column="idLocalPort" not-null="true"/>
      <many-to-one access="field" class="RemotePort" name="RemotePort" column="idRemotePort" not-null="true"/>
      <many-to-one access="field" class="RemoteAddress" name="RemoteAddress" column="idRemoteAddress" not-null="true"/>
      <property access="field" name="BytesSent" column="bytesSent" not-null="true"/>
      <property access="field" name="BytesReceived" column="bytesReceived" not-null="true"/>
      <many-to-one access="field" class="ProtocolType" name="ProtocolType" column="idProtocolType" not-null="true"/>
      <many-to-one access="field" class="Computer" name="Computer" column="idComputer" not-null="true"/>
      <many-to-one access="field" class="User" name="User" column="idUser" not-null="true"/>
   </class>
</hibernate-mapping>


You can see that table-per-concrete class inheritance mapping is used.

Fisrt query succeeded, second one returned an exception:
"in expected: <end-of-text> (possibly an invalid or unmapped class name was used in the query) [FROM EventFact]"

Code:
ICriteria crit = project.Session.CreateCriteria(typeof(EventFact));
crit.List();

IQuery query = project.Session.CreateQuery("FROM EventFact");
uery.List();




sergey wrote:
You have an error on line 33 of your application!

Seriously, it should work but how can we know why it doesn't? Give us details.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 28, 2007 5:33 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You have to use <import> to import the class name so that the HQL parser knows about it. Something like:
Code:
<import class="IDS.Domain.EventFact, IDS.Domain" />


Top
 Profile  
 
 Post subject: Thanks!!! It works now.
PostPosted: Mon May 28, 2007 5:48 pm 
Beginner
Beginner

Joined: Tue Aug 23, 2005 8:15 am
Posts: 45
sergey wrote:
You have to use <import> to import the class name so that the HQL parser knows about it. Something like:
Code:
<import class="IDS.Domain.EventFact, IDS.Domain" />


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 04, 2007 3:53 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 10:32 am
Posts: 34
sergey wrote:
You have to use <import> to import the class name so that the HQL parser knows about it. Something like:
Code:
<import class="IDS.Domain.EventFact, IDS.Domain" />


Thanks! - this helps us also.
Actually, we do write an additional "mapping file" for such a class which contains only the <import> clause.

Regards
Harald


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