-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria and recover specific list
PostPosted: Thu Apr 21, 2011 12:10 pm 
Newbie

Joined: Mon Apr 18, 2011 3:03 am
Posts: 5
Hello,

En ce moment je suis en train d'essayer de récupérer seulement certains champs particuliers d'une classe/table. Pour se faire j'utilise Criteria avec les projections. Voici le mapping de la classe/table dont je veux récupérer certaines données :
Right now I'm trying to retrieve only specific fields of a class / table.
I use to make Criteria with the projections.

Here is the mapping of the class / table that I want to retrieve some data:

Code :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">

  <class name="Business.Model.Origination.OrigineElement, Business.Production" table="SystemTableOrigination.TElementOrigine"  >
    <cache usage="read-write" />
    <id name="Id" column="Id" type="System.Int32" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property name="Number" column="Numero" not-null="true" type="System.String"/>
    <property name="Description" column="Description" not-null="false" type="System.String"/>
    <property name="Observation" column="Observation" not-null="false" type="System.String"/>
    <property name="Poids" column="Poids" type="System.String" not-null="false"/>
    <property name="Dvd" column="CDDVD" type="System.String" not-null="false"/>

    <bag name="DonorTaker" lazy="false" inverse="true">
      <key column="ElementOrigineId"/>
      <one-to-many class="Business.Model.DonorTaker.DonorTaker, Business.Production"/>
    </bag>
  </class>
</hibernate-mapping>


The class :

Code :
Code:
    [DataContract]
    public class OrigineElement : Business.Model.Production.Common.EntityBase, IElement
    {
        [DataMember] public virtual string Number { get; set; }
        [DataMember] public virtual string Description { get; set; }
        [DataMember] public virtual string Observation { get; set; }
        [DataMember] public virtual IList<Business.Model.DonorTaker.DonorTaker> DonorTaker { get; set; }
        [DataMember] public virtual string Poids { get; set; }
        [DataMember] public virtual string Dvd { get; set; }
}



My criteria :

Code :
Code:
ICriteria crit = session.CreateCriteria(OrigineElement)
                .Add(Projections.Alias(Projections.Property("Number"), "Number"))
                .Add(Projections.Alias(Projections.Property("Description"), "Description"))
                .Add(Projections.Alias(Projections.Property("DonorTaker"), "DonorTaker"))
                .Add(Restrictions.Eq("Id", "50"));
                crit.SetResultTransformer(
                new NHibernate.Transform.AliasToBeanResultTransformer(OrigineElement));
                result = (OrigineElement)crit.UniqueResult();



the result returns me an object property with the right number, the correct description by my cons list DonorTaker type object is null then what should contain more objects.

It's here i have a problem !

Thx !

Bye

PS : sorry if my language is horrible, but i am french ;)


Top
 Profile  
 
 Post subject: Re: Criteria and recover specific list
PostPosted: Fri Apr 22, 2011 6:08 am 
Newbie

Joined: Mon Apr 18, 2011 3:03 am
Posts: 5
In fact it is not possible because a projection is necessarily composed of a single query. I think that is possible using subqueries but I have not yet succeeded (if someone has something to add ... an idea ...


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