-->
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.  [ 9 posts ] 
Author Message
 Post subject: IQuery and joined-subclass
PostPosted: Sat Jan 12, 2008 2:58 pm 
Newbie

Joined: Fri Dec 21, 2007 1:17 pm
Posts: 11
I have a problem quering for a joined-subclass property
Situation:

class A joined-subclass B (with a property "prop")
class C associated with A

example query:

from C c INNER JOIN c.A a GROUP BY a.prop

I obtain an ADOException referring a table that does not exists.

Is there a way to query for the joined-subclass ?

Best Regars.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 3:02 pm 
Newbie

Joined: Fri Dec 21, 2007 1:17 pm
Posts: 11
I forgot to say that if B is subclass and not joined-subclass of A the query works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 5:23 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Can you provide the mapping files, the tables involved and the class files?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 8:41 pm 
Newbie

Joined: Fri Dec 21, 2007 1:17 pm
Posts: 11
Sure!

I cut off many things to make the example as simple as possible.

This is the mapping:

Code:
<class name="Task" table="Task">
      <id name="Id" column="Id" type="Int64">
         <generator class="identity"/>
      </id>
      <set name="Risorse" inverse="true" cascade="save-update">
         <key column="Task_Id"/>
         <one-to-many class="Risorsa"/>
      </set>
      <property name="StatoTask"/>
      <property name="TipoTask" type="Simplico.Business.Seteco.Entities.EnumTipoTask, SetecoEntities"/>
      <property name="DataInizio" type="Date"/>
      <property name="DataFine" type="Date"/>
      <property name="PercentualeCompletamento" type="Single"/>
   </class>

   <class name="Risorsa" table="Risorsa">
      <id name="Id" column="Id" type="Int64">
         <generator class="identity"/>
      </id>
      <many-to-one name="TaskGS" class="Task" column="Task_Id" foreign-key="fk_Risorsa_Task"/>
      <property name="DataInizio" type="Date"/>
      <property name="DataFine" type="Date"/>
      <property name="DataInserimento" type="Date"/>

      <joined-subclass name="RisorsaEconomica" table="RisorsaEconomica">
         <key column="Risorsa_Id"/>
         <property name="Valore" type="Decimal"/>
      </joined-subclass>

      <joined-subclass name="RisorsaUomo" table="RisorsaUomo">
         <key column="Risorsa_Id"/>
         <property name="Ore" type="Single"/>
         <many-to-one name="RelazioneGS" class="Simplico.Business.Anagrafica.Entities.Relazione" column="Relazione_Id" foreign-key="fk_Risorsa_Relazione"/>
      </joined-subclass>
   </class>


And this is a sample query:

Code:
string qry = "SELECT sum(ris.Ore) FROM Task t INNER JOIN t.Risorse ris GROUP BY ris.DataInizio";


The resulting query is:

Code:
select sum(risorse1_2_.Ore) as x0_0_ from Task task0_ inner join Risorsa risorse1_ on task0_.Id=risorse1_.Task_Id group by  risorse1_.DataInizio


The resulting error is quite obvious, risorse1_2_ doesn't exist.
Changing the mapping file having only one table for the hierarchy, with discriminators, everything goes fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 8:49 pm 
Newbie

Joined: Fri Dec 21, 2007 1:17 pm
Posts: 11
Ops... the classes:

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace Simplico.Business.Seteco.Entities
{
    public abstract class Risorsa
    {
        private long m_id;
        protected Task m_task;
        protected DateTime m_dataInizio;
        protected DateTime m_dataFine;
        protected DateTime m_dataInserimento;

        public Risorsa() { }
        public virtual long Id { get { return m_id; } set { m_id = value; } }
        public virtual Task TaskGS { get { return m_task; } set { m_task = value; } }
        public virtual DateTime DataInserimento { get { return m_dataInserimento; } set { m_dataInserimento = value; } }
        public virtual DateTime DataInizio { get { return m_dataInizio; } set { m_dataInizio = value; } }
        public virtual DateTime DataFine { get { return m_dataFine; } set { m_dataFine = value; } }

    }
}


using System;
using System.Collections.Generic;
using System.Text;
using Simplico.Business.Anagrafica.Entities;
using Simplico.Business.ModuleJoin.Entities;
using Simplico.Persistence.NHibernate;
using NHibernate;
using System.Collections;
using Simplico.Business.Contabilita.Entities;

namespace Simplico.Business.Seteco.Entities
{
    public class RisorsaUomo : Risorsa
    {
        float m_ore;

        public RisorsaUomo() { }
        public virtual float Ore { get { return m_ore; } set { m_ore = value; } }
        public override DateTime DataFine { get { return DataInizio; } set { DataInizio = value; } }
    }
}

using System;
using System.Collections.Generic;
using System.Text;
using Simplico.Business.Entity;
using Iesi.Collections.Generic;

namespace Simplico.Business.Seteco.Entities
{
    public enum EnumStatoTask { APERTO, CHIUSO }
    public enum EnumTipoTask { PROGETTO_DEFINITIVO, DIREZIONE_LAVORI }

    public class Task
    {
        private long m_id;
        EnumTipoTask m_tipo;
        EnumStatoTask m_stato;
        ISet<Risorsa> m_risorse = new HashedSet<Risorsa>();
        DateTime m_dataInizio;
        DateTime m_dataFine;
        Opera m_opera;
        Commessa m_commessa;
        float m_completamento;

        public Task() { }
        public virtual long Id { get { return m_id; } set { m_id = value; } }
        public virtual EnumTipoTask TipoTask { get { return m_tipo; } set { m_tipo = value; } }
        public virtual ISet<Risorsa> Risorse { get { return m_risorse; } set { m_risorse = value; } }
        public virtual EnumStatoTask StatoTask { get { return m_stato; } set { m_stato = value; } }
        public virtual DateTime DataInizio { get { return m_dataInizio; } set { m_dataInizio = value; } }
        public virtual DateTime DataFine { get { return m_dataFine; } set { m_dataFine = value; } }
        public virtual float PercentualeCompletamento { get { return m_completamento; } set { m_completamento = value; } }
    }
}


I hope I did't forget anything more.
The tables are those created by the SchemaExport class.[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 9:56 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
maybe this is part of what you left out to make it simpler, but, if you are not limiting by task at all, why not do the sum() and the group by directly on Risorce?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 11:05 pm 
Newbie

Joined: Fri Dec 21, 2007 1:17 pm
Posts: 11
Yes I need Task and much more :)
The solution with only one table is good enough for me, but I was wondering if this is a bug or an error of mine ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 12, 2008 11:18 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
In principle, I see nothing wrong. The join in your mapping is valid, the property exists...

Try leaving all joins implicit in your HQL, something like

SELECT sum(t.Risorce.Ore) FROM Task t
...
<your where condition(s) here>
...
GROUP BY t.Risorce.DataInizio

This probably won't work either, but the generated SQL might give you a clue on why the parser is inventing that table alias.

Alternatively, try do the grouping after-the-fact, using a Criteria query and a Projection.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 13, 2008 7:56 am 
Newbie

Joined: Fri Dec 21, 2007 1:17 pm
Posts: 11
I'll try your suggestions.
Thanks a lot for your help and time :)


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