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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:58:24+00:00 2026-05-15T23:58:24+00:00

I have a simple jpa entity ‘ApplicationForm’ with a one to many list in

  • 0

I have a simple jpa entity ‘ApplicationForm’ with a one to many list in it:

 @OneToMany(cascade=CascadeType.REMOVE, mappedBy="textQuestion")
 private List<Dictionary> questions;

The variable Dictionary contained in ApplicationForm is just another plain entity with just the text of the question.
The corresponding database table mapped by Dictionary is:

'locale' 'text'      'formId'
en       my question 123 
it       mia domanda 123

I was wondering if it’s possible with jpa or hibernate, to build a query for retrieving an ApplicationForm entity with a Dictionary for a specific locale, for example ‘it’ only.
That would be easy enough to do with standard sql, but I cannot translate in hql.

If not possible, could you suggest an alternative way ? I have tried to manually iterate the Dictionary questions list and remove the not required locale, but is not really elegant, and also I got a jpa/hibernate error.

I hope I made myself clear, and code supplied is enough.

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-05-15T23:58:25+00:00Added an answer on May 15, 2026 at 11:58 pm

    I was wondering if it’s possible with jpa or hibernate, to build a query for retrieving an ApplicationForm entity with a Dictionary for a specific locale, for example ‘it’ only.

    Not with standard JPA. But Hibernate allows to apply arbitrary filters to a collection load during a given session. From the Hibernate Annotations Reference Guide:

    2.4.8. Filters

    Hibernate has the ability to apply
    arbitrary filters on top of your data.
    Those filters are applied at runtime
    on a given session. First, you need to
    define them.

    @org.hibernate.annotations.FilterDef
    or @FilterDefs define filter
    definition(s) used by filter(s) using
    the same name. A filter definition has
    a name() and an array of
    parameters(). A parameter will allow
    you to adjust the behavior of the
    filter at runtime. Each parameter is
    defined by a @ParamDef which has a
    name and a type. You can also define a
    defaultCondition() parameter for a
    given @FilterDef to set the default
    condition to use when none are defined
    in each individual @Filter. A
    @FilterDef(s) can be defined at the
    class or package level.

    We now need to define the SQL filter
    clause applied to either the entity
    load or the collection load. @Filter
    is used and placed either on the
    entity or the collection element

    @Entity
    @FilterDef(name="minLength", parameters=@ParamDef( name="minLength", type="integer" ) )
    @Filters( {
        @Filter(name="betweenLength", condition=":minLength <= length and :maxLength >= length"),
        @Filter(name="minLength", condition=":minLength <= length")
    } )
    public class Forest { ... }
    

    When the collection use an association
    table as a relational representation,
    you might want to apply the filter
    condition to the association table
    itself or to the target entity table.
    To apply the constraint on the target
    entity, use the regular @Filter
    annotation. However, if you wan to
    target the association table, use the
    @FilterJoinTable annotation.

    @OneToMany
    @JoinTable
    //filter on the target entity table
    @Filter(name="betweenLength", condition=":minLength <= length and :maxLength >= length")
    //filter on the association table
    @FilterJoinTable(name="security", condition=":userlevel >= requredLevel")
    public Set<Forest> getForests() { ... }
    

    See also

    • Chapter 17. Filtering data In the Hibernate Core Reference Documentation.
    • Hibernate3 Filters
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple JPA/JPQL question. I have an entity with a ManyToMany relationship: @Entity public class
I have a simple question regarding Entity declaration in JPA. I have an entity
I develop tools in Autodesk Maya. Many of the tools I build have simple
I have a pretty simple JPA @ManyToMany relationship set up in my application. A
A have a JPA entity that has timestamp field and is distinguished by a
I have a simple entity, Code, that I need to persist to a MySQL
I am trying to generate a unidirectional one-to-many mapping between two JPA entities. In
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement

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.