-->
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.  [ 1 post ] 
Author Message
 Post subject: Obtain a list of objects from the HQL sentence
PostPosted: Tue Dec 04, 2007 11:58 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Hello forum, I've a doubt because I don't know how translate a query to list of objects.

I have a Stock object as -->



Code:
public class Stock
    {
        private Model.Consulting.StockId id;
        private int quantity;

        protected Stock () {
            this.id = new StockId();
            this.quantity = -1;
        }

        public Stock(Model.Entities.ComplexArticle article, Model.Entities.Place site, int quantity)
        {
            this.id = new StockId(article, site);
            this.quantity = quantity;
        }

        #region Properties

        public virtual Model.Consulting.StockId Id { get { return id; } set { id = value; } }

        public virtual Model.Entities.ComplexArticle Article { get { return this.id.Article; } set { this.id.Article = value; } }

        public virtual Model.Entities.Place Site { get { return this.id.Site; } set { this.id.Site = value; } }

        public virtual int Quantity { get { return quantity; } set { quantity = value; } }

        public virtual double Value { get { return this.id.Article.Price * this.quantity; } }

        #endregion

    }

    public class StockId
    {
        private Model.Entities.ComplexArticle article;
        private Model.Entities.Place site;

        public StockId()
        {
            this.article = null;
            this.site = null;
        }

        public StockId(Model.Entities.ComplexArticle article, Model.Entities.Place site)
        {
            this.article = article;
            this.site = site;
        }

        #region Properties

        public virtual Model.Entities.ComplexArticle Article { get { return article; } set { article = value; } }

        public virtual Model.Entities.Place Site { get { return site; } set { site = value; } }

        #endregion

        #region ToString, Equals, HashCode

        public override bool Equals(object obj)
        {
            if (this == obj) return true;
            if (obj == null || !obj.GetType().Equals(this.GetType())) return false;

            Model.Consulting.StockId altre = (Model.Consulting.StockId)obj;
            return this.Article == altre.Article && this.Site == altre.Site;
        }

        public override int GetHashCode()
        {
            return this.Site.GetHashCode() + this.Article.GetHashCode() + 74;
        }

        #endregion
    }


And I need to execute this sentence-->
Code:
SELECT ARTICLE_ID, TO_PLACE_ID SITE, CAST(AMOUNT AS SIGNED INT) QUANTITY FROM STOCK_MOVEMENTS WHERE TO_PLACE_ID IS NOT NULL


How Can I translate the result sentence to list of Stock objects?
I will appreciate very much your help.
Thanks for all in advanced.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.