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 7013807
In Process

The Archive Base Latest Questions

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

I have a product table: Product – PId – Name ProductPricing – PPId –

  • 0

I have a product table:

Product
- PId
- Name

ProductPricing
- PPId
- PId
- startDate
- endDate
- price

For one product, there can be multiple ProductPricing records.

For retrieving current price for the product, I use the following query:

SELECT PId, Name, price, startDate, endDate
FROM PRODUCT, PRODUCTPRICING
WHERE PRODUCT.PId = givenId AND PRODUCT.PId = PRODUCTPRICING.PId
AND (today() > PRODUCTPRICING.startDate AND today() < PRODUCTPRICING.endDate);

How do I map the result of this query to my POJO using Hibernate ??

my Java Product object looks something like this:

Product
- Id
- Name
- ProductPricing Object

ProductPricing
- startDate
- endDate
- price
  • 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-27T22:26:21+00:00Added an answer on May 27, 2026 at 10:26 pm

    This will give a slightly different query (with a sub-query instead of a join), but the result should be the same.

    @Entity
    class Product
    {
    @Id
    int id;
    String name;
    @Formula("(select pp.price from PRODUCTPRICING pp where pp.PId = id and today() > pp.startDate AND today() < pp.endDate )")
    double price;
    }
    

    If you want to map the ProductPricing as a POJO, too, I think you can’t map it as a one-to-one, since it’s technically a one-to-many with a filter which will hopefully result in only one result. So you’ll have a Set<ProductPricing> in your Product class:

    <set name="prices" table="PRODUCTPRICING">
      <key column="PId"/>
      <composite-element class="ProductPricing">
        <property name="price"/>
        <property name="startdata"/>
        <property name="enddate"/>
      </composite-element>
      <filter condition="today() > startDate AND today() < endDate"/>
    </set>
    

    With composite-element, you don’t need a primary key PPId in the PRODUCTPRICING table.

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

Sidebar

Related Questions

I have 2 tables product and history product table: id name type price location
I have two tables as follows PRODUCT table Id | Name | Price And
I have a table of product information with many bit columns. This table can
I have a product table like this: Product name , Affiliate ID , ProductCode
I have a product table called products It has 3 fields (name,model(PK), and class_name).
I have a product table and a detail table Product ID int Price int
I currently have the following Product table: Product _______ id, INT name, String featured,
I have two tables: **Product** ID Name SKU **Brand** ID Name Product table has
I have about 10,000 products in the product table. I want to retrieve one
I have 2 tables, a product table and an image table. Products can have

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.