-->
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.  [ 10 posts ] 
Author Message
 Post subject: createQuery problem
PostPosted: Wed Mar 31, 2004 5:29 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi All,

Maps:

Code:
    <class name="com.db.device.NEMgmtInfo" table="nemgmtinfo" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false">
      <!--cache usage="read-write" /-->
      <id name="id" type="long" unsaved-value="0">
         <generator class="native">
         </generator>
      </id>

      <many-to-one name="sflowAgent" class="com.db.device.SflowAgent" cascade="all"/>
    </class>

    <class name="com.db.device.FlowMonAgent" table="FlowMonAgent" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false">
      <id name="id" type="long" unsaved-value="0">
         <generator class="native" />
      </id>

        <property name="ipAddress" type="com.db.device.IPV4AddressType">
           <column name="address_"/>
           <column name="mask_"/>
        </property>
       
        <property name="opState" type="com.db.device.OperationalStatus"/>
        <property name="adminState" type="com.db.device.AdminStatus"/>
       
        <property name="ipPort" column="ip_port" type="integer"/>
      <many-to-one name="pollingInterval" class="com.db.qos.valuewithunits.TimeInterval" cascade="all"/>
      <many-to-one name="samplingInterval" class="com.db.qos.valuewithunits.TimeInterval" cascade="all"/>
        <property name="useMgmtIPAddressAsFlow" type="boolean"/>
       
        <joined-subclass name="com.db.device.SflowAgent" table="SflowAgent">
         <key column="id"/>
        </joined-subclass>
       
        <joined-subclass name="com.db.device.NetFlowAgent" table="NetflowAgent">
         <key column="id"/>
        </joined-subclass>
     </class>

and trying to execute:

Code:
         q = sess.getPersistentSession().createQuery(
         "select new com.db.device.NEMgmtInfoLightweight( "+
         "nemgmtinfo.sflowAgent" +
         ") "+
         
         "from com.db.device.NEMgmtInfo as nemgmtinfo");


where

Code:
public class NEMgmtInfoLightweight extends NEMgmtInfo implements Serializable {

   public NEMgmtInfoLightweight() {
   }

   public NEMgmtInfoLightweight(
      SflowAgent sflowAgent
      ) {
      super.setSflowAgent((SflowAgent)sflowAgent);
   }

}


Surprinsingly, the generated query does not return anything from the DB (there are records in there) and NO ERROR is produced:

Hibernate:
Code:
   select sflowagent1_.id as id,
      sflowagent1__1_.address_ as address_33_,
      sflowagent1__1_.mask_ as mask_33_,
      sflowagent1__1_.opState as opState33_,
      sflowagent1__1_.adminState as adminState33_,
      sflowagent1__1_.ip_port as ip_port33_,
      sflowagent1__1_.pollingInterval as pollingI7_33_,
      sflowagent1__1_.samplingInterval as sampling8_33_,
      sflowagent1__1_.useMgmtIPAddressAsFlow as useMgmtI9_33_
   from nemgmtinfo nemgmtinfo0_,
      SflowAgent sflowagent1_
   left outer join FlowMonAgent sflowagent1__1_ on
      sflowagent1_.id=sflowagent1__1_.id where nemgmtinfo0_.sflowAgent=sflowagent1_.id


What's wrong here?

Please Help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 6:43 pm 
Newbie

Joined: Mon Feb 09, 2004 1:40 am
Posts: 13
Location: Moscow, Russia
Did you try execute SQL query from SQL console?
Does it produce non-empty result set?

_________________
God is Real, unless declared as Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 6:51 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
dimitry wrote:
Did you try execute SQL query from SQL console?
Does it produce non-empty result set?


Thx for the answer.

I am not sure what values to provide for the arguments.

I am not a keen SQL (that's why I chose Hibernate) but it looks to me the query is trying to select from sflowagent (which is empty) instead of selecting everything from nemgmtinfo and fill in the sflowAgent attribute !


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:07 pm 
Newbie

Joined: Mon Feb 09, 2004 1:40 am
Posts: 13
Location: Moscow, Russia
Quote:
select new com.db.device.NEMgmtInfoLightweight( nemgmtinfo.sflowAgent)


Quoted part of query forces Hibernate select from sflowagent.

If you want to avoid it (select instances with sflowAgent==null), try smth like:
Code:
select new com.db.device.NEMgmtInfoLightweight(sflowAgent)
from com.db.device.NEMgmtInfo as nemgmtinfo
  right outer join nemgmtinfo.sflowAgent sflowAgent

_________________
God is Real, unless declared as Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:18 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
dimitry wrote:
Quote:
select new com.db.device.NEMgmtInfoLightweight( nemgmtinfo.sflowAgent)


Quoted part of query forces Hibernate select from sflowagent.

If you want to avoid it (select instances with sflowAgent==null), try smth like:
Code:
select new com.db.device.NEMgmtInfoLightweight(sflowAgent)
from com.db.device.NEMgmtInfo as nemgmtinfo
  right outer join nemgmtinfo.sflowAgent sflowAgent


thx again.
Actually I want to select all nemgmtinfo instances and fill in the sflowAgent member in the obtained nemgmtinfo instances.

The suggestion above didn't do the trick.
More help, please :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:26 pm 
Newbie

Joined: Mon Feb 09, 2004 1:40 am
Posts: 13
Location: Moscow, Russia
Hmm..
Why you can't use simple 'select nemgmtinfo from com.db.device.NEMgmtInfo as nemgmtinfo'?

_________________
God is Real, unless declared as Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 8:06 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
dimitry wrote:
Hmm..
Why you can't use simple 'select nemgmtinfo from com.db.device.NEMgmtInfo as nemgmtinfo'?


Because I don't want to pull from the db all the attributes for nemgmtinfo.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 8:30 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
A question:

Why is so a problem for Hibernate to only load specific fields of an object?

It is so simple in JDO, by using fetch groups:

Query q = (Query) pm.newQuery (GroupExample.class, ...);
q.getFetchConfiguration ().addFetchGroup ("g1");
Collection results = (Collection) q.execute ();

Could we have something similar in Hibernate?

thx.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:34 pm 
Newbie

Joined: Mon Feb 09, 2004 1:40 am
Posts: 13
Location: Moscow, Russia
What su you think about use explicit polymorphism?
http://www.hibernate.org/41.html

_________________
God is Real, unless declared as Integer.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 10:47 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
dimitry wrote:
What su you think about use explicit polymorphism?
http://www.hibernate.org/41.html


Yeah, it's a half-way solution...
This would expand the domain model, though.

thx again.


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