Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6830301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:36:06+00:00 2026-05-26T22:36:06+00:00

please excuse my bad English… In my database there are stored article sets. In

  • 0

please excuse my bad English…

In my database there are stored article sets. In every article sets there are several different articles in it. Each article has a different demand with a date and a quantity.

In the project there is an enum which looks like this:

public enum PeriodDefinition {
    Individual,
    Day,
    Week,
    Month,
    Quarter,
    HalfYear,
    Year
}

The entity of Article is like that:

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;

@Entity
public class Article extends ArticleContainer {
    private float price;

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
}

The entity of Article Container:

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToOne;

@Entity
public class ArticleContainer extends BaseEntity {

    @Column(nullable = false, unique = true)
    private String number;

    @Column(nullable = false)
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

}

The Entity of Article Set:

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

@Entity
public class ArticleSet extends ArticleContainer {

    private static final long serialVersionUID = 6236522228097421880L;

    @ManyToMany
    private List<Article> articles = new ArrayList<Article>();

    @OneToMany
    private List<ArticleSet> children = new ArrayList<ArticleSet>();


    public List<Article> getArticles() {
        return articles;
    }

    public void setArticles(List<Article> articles) {
        this.articles = articles;
    }

    public List<ArticleSet> getChildren() {
        return children;
    }

    public void setChildren(List<ArticleSet> children) {
        this.children = children;
    }

}

And finally the Demand entity

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
public class Demand extends BaseEntity {
    @ManyToOne(optional = false)
    private Article article;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(nullable = false)
    private Date demandTime;

    private double quantity;

    public Article getArticle() {
        return article;
    }

    public void setArticle(Article article) {
        this.article = article;
    }

    public Date getTimeStamp() {
        return demandTime;
    }

    public void setTimeStamp(Date demandTime) {
        this.demandTime = demandTime;
    }

    public double getQuantity() {
        return quantity;
    }

    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }

}

For example there exists an article set with the name “ArticleSetOfTwo” and the number 002 and contains the articles “Article 1” and “Article 2” with the numbers 1 and 2.

Article 1 has the following demand: (Left is date and right is quantity)

  • 07-11-2011, 10
  • 08-11-2011, 50
  • 15-11-2011, 200
  • 15-11-2011, 300
  • 16-11-2011, 100

Article 2 has the following demand:

  • 08-11-2011, 20
  • 09-11-2011, 10
  • 14-11-2011, 150
  • 15-11-2011, 150
  • 16-11-2011, 100

Now I want to sum all quantities in the article set divided by a period of our enum, e.g. week. Then this would be for the Articleset:

For the first week starting at 07-11-2011 until 13-11-2011 it would be: 90

For the second week starting at 14-11-2011 until 20-11-2011 it would be: 1000

These values I’d like to store in a ArrayList but I don’t know how to do it. Maybe someone can solve it. Thank you very much in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:36:06+00:00Added an answer on May 26, 2026 at 10:36 pm

    I’m not sure it’s doable using a query.

    I would just select all the date/quantity pairs for the article set, ordered by date, and then do a loop starting from the start date and ending with the end date, and add the quantities in Java.

    The HQL would look like this:

    select d.demandTime, d.quantity from Demand d, ArticleSet set 
    inner join set.articles article 
    where d.article = article
    order by d.demandTime
    

    Then, for each week, loop through the pairs and, if the demand time is between the start and the end of the week, add the quantity of the demand to the week sum.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, please excuse me for my bad english!:) Im developing several mods
Hello (please excuse me for my bad english ;) ), Imagine the classes bellow:
First of all please excuse me for my bad English speaking. I am new
Please excuse any mistakes in terminology. In particular, I am using relational database terms.
Please excuse me if there are already answers to this, but I can't quite
Please excuse my english, I'm still trying to master it. I've started to learn
Please excuse me if this is a noob question. I have tried every possibility
first of all: please excuse my english. It's not my natural tongue. I have
I am very new to programming so please excuse me if there is an
Please excuse my english i use translator. Let's say i have on my website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.