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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:55:32+00:00 2026-06-07T06:55:32+00:00

I have a question about Hibernate ManyToOne association. I have a Product entity mapped

  • 0

I have a question about Hibernate ManyToOne association.

I have a Product entity mapped like this:

public class Product {
@Id
@DocumentId
@Column(name = "PRODUCT_ID", columnDefinition = "integer")
@Index(name = "PRODUCT_ID_IDX")
private Long id;

@Column(name = "SALE_PRICE")
@Index(name = "PRODUCT_PRICE_IDX")
private Double salePrice;
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "CATEGORY_ID", nullable = true)
@Index(name = "PRODUCT_ID_CATEGORY_IDX")
private ProductCategory category;
}

So how can you see we have relationship with ProductCategory table. And FK we store in Product table.
When I create query which select Product by specific category and price I have next SQL:
select
this_.PRODUCT_ID as PRODUCT1_9_1_,
this_.BUY_URL as BUY2_9_1_,
this_.CATEGORY_ID as CATEGORY15_9_1_,
this_.CURRENCY as CURRENCY9_1_,
this_.IMAGE_URL as IMAGE4_9_1_,
this_.INSTOCK as INSTOCK9_1_,
this_.LONG_DESCRIPTION as LONG6_9_1_,
this_.NAME as NAME9_1_,
this_.RATING as RATING9_1_,
this_.RETAIL_PRICE as RETAIL9_9_1_,
this_.SALE_PRICE as SALE10_9_1_,
this_.SHIPPING as SHIPPING9_1_,
this_.SHORT_DESCRIPTION as SHORT12_9_1_,
this_.UPC as UPC9_1_,
this_.VIEWS as VIEWS9_1_,
cat1_.CATEGORY_ID as CATEGORY1_10_0_,
cat1_.NAME as NAME10_0_,
cat1_.RATING as RATING10_0_,
cat1_.VIEWS as VIEWS10_0_,
cat1_.VISIBLE as VISIBLE10_0_
from
PRODUCT this_
inner join
PRODUCT_CATEGORY cat1_
on this_.CATEGORY_ID=cat1_.CATEGORY_ID
where
(
this_.SALE_PRICE between ? and ?
and cat1_.CATEGORY_ID in (
?
)
)
order by
this_.NAME asc limit ? offset ?

My question is next: How do I can avoid inner join of two tables: Product and ProductCategory?

My Criteria DAO code:
criteria.createAlias("category", "cat");
criteria.add(Restrictions.conjunction()
.add(Restrictions.between("salePrice", priceLow, priceHigh))
.add(Restrictions.in("cat.id", categoryIds)));

Thanks.

  • 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-06-07T06:55:35+00:00Added an answer on June 7, 2026 at 6:55 am

    The line

    criteria.createAlias("category", "cat");
    

    precisely means: create an inner join with the Category entity.

    Just use

    criteria.add(
        Restrictions.conjunction()
            .add(Restrictions.between("salePrice", priceLow, priceHigh))
            .add(Restrictions.in("category.id", categoryIds)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about how Hibernate persists entity relations. Let's say I have
I have a general question about Hibernate that I'm batteling with. I have class
Does anybody have any idea about unions in hibernate? I got this question in
I have question about parsing in Html helper : I have sth like: @foreach
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I have a design question about the use of Hibernate annotations and DAO pattern.
I have a question about Hibernate. I'm using 3.1.3 version and I have two
I have a simple question about usage of Hibernate. I keep seeing people using
Ok, I have this spring hibernate xml configuration. <bean id=sessionFactory class=org.springframework.orm.hibernate3.LocalSessionFactoryBean> <property name=dataSource ref=dataSource
I have a question about JPA-2.0 (provider is Hibernate) relationships and their corresponding management

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.