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

  • Home
  • SEARCH
  • 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 8713263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:18:10+00:00 2026-06-13T05:18:10+00:00

I am building a category-based web application multilanguage using JPA/Hibernate + Spring I currently

  • 0

I am building a category-based web application multilanguage using JPA/Hibernate + Spring

I currently built these three beans/entities: Category, CategoryLanguage and Language.

Category:

@Entity
public class Category implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    @ManyToOne
    private Category father;
    @OneToMany(mappedBy = "father")
    private List<Category> children;
    @OneToMany(mappedBy="category")
    private List<CategoryLanguage> categoryLanguages;

CategoryLanguage:

@Entity
public class CategoryLanguage implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    @ManyToOne
    Category category;
    @Column(length = 20, nullable = false)
    private String name;
    @ManyToOne
    private Language language;

and Language

public class Language implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(length=2)
    private String id; // en, de, fr, it, es,...
    
    @Column(length=25)
    private String name; // English, Deutsch, Français,...

By calling

from Category c join c.categoryLanguages cl where c.father = null and cl.language.id = :lang

It returns the first level of categories with the right language, but contains all the languages as children.

Children are extracted for every language instead of the one I chose on the query.

What could I do to solve this problem? I can not use "join on" in JPQL, can i?

  • 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-13T05:18:11+00:00Added an answer on June 13, 2026 at 5:18 am

    Your query is asking for complete Category entities, and so you cannot accomplish what you want strictly with JPA. JPA requires that the category entities returned reflect the data that is in the database – this includes all CategoryLanguages regardless of the language they might correspond to in the selecting query.

    What you might want to do instead is to rearrange the query differently. In this case, query for the CategoryLanguage entities associated to the Language you want, and then use it to obtain the Category. The category->CategoryLanguage relation will still be populated, but your query only returns the CategoryLanguage representing the language you want without any other languages. Key these by Category to make it easier if you want.

    Most providers do allow adding filtering criteria to the mappings directly, or you can even use queries that only return partial entities, but I caution you to avoid going down that route. Once you do, it is difficult to maintain the app and manage the data correctly, and can end up limiting performance options such as caching. For instance, once you have all the partial category entity and want to add a new CategoryLanguage or make any other change, how do you handle it? Merge would not work since it would cause any CategoryLanguage not in the list from the database

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

Sidebar

Related Questions

I am building a web application on google app engine using python and jinja2.
Building a new ASP.net application, and planning to separate DB, 'service' tier and Web/UI
I'm building a web app using EF Code First and ASP.NET MVC. I have
Thinking of building a nested category system using chained strings for lack of a
I'm building a category manager via database. The following PHP generates the code I'll
I have a problem with building multi level select box. I have category table
So here's the scenario, I'm building a theme that would display sub category of
Building an inventory system. I have lots of products and each product has three
Building a new Mobile Web Platform for Mobile Users to purchase & download content
building a site using PHP and MySQL that needs to store a lot of

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.