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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:49:02+00:00 2026-05-16T20:49:02+00:00

@Entity public class Person { @ElementCollection private List<Location> locations; […] } @Embeddable public class

  • 0
    @Entity
    public class Person {

        @ElementCollection
        private List<Location> locations;

        [...]

    }

    @Embeddable
    public class Location {

        private Integer dummy;

        private Date creationDate;

        [...]

    }

Given the following structure, I’d like to perform the HQL or CriteriaQuery equivalent of the following SQL:

SELECT
    l.*
FROM
    Location l
INNER JOIN
    Person p ON (p.id = l.person_id)
WHERE
    p.id = ? AND l.creationDate > ?

I want to get back a list of Locations that are associated with the given person and whose creationDate is after the given one.

Thanks in advance!

Mark

Edit***: I have edited the SQL, as it was kinda misleading. I don’t want to query for the locations independently.

  • 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-16T20:49:03+00:00Added an answer on May 16, 2026 at 8:49 pm

    This is not possible, you cannot query an Embeddable. From the JPA Wikibook:

    Embedded Collections

    An ElementCollection mapping can be
    used to define a collection of
    Embeddable objects. This is not a
    typical usage of Embeddable objects
    as the objects are not embedded in the
    source object’s table, but stored in a
    separate collection table. This is
    similar to a OneToMany, except the
    target object is an Embeddable
    instead of an Entity. This allows
    collections of simple objects to be
    easily defined, without requiring the
    simple objects to define an Id or
    ManyToOne inverse mapping.
    ElementCollection can also override
    the mappings, or table for their
    collection, so you can have multiple
    entities reference the same Embeddable
    class, but have each store their
    dependent objects in a separate table.

    The limitations of using an
    ElementCollection instead of a
    OneToMany is that the target
    objects cannot be queried
    ,
    persisted, merged independently of
    their parent object. They are strictly
    privately-owned (dependent) objects,
    the same as an Embedded mapping.
    There is no cascade option on an
    ElementCollection, the target
    objects are always persisted, merged,
    removed with their parent.
    ElementCollection still can use a
    fetch type and defaults to LAZY the
    same as other collection mappings.

    To achieve what you want, use a OneToMany and an Entity instead of an ElementCollection and an Embeddable. Or change your approach and query the Person.

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

Sidebar

Related Questions

@Entity public class TestClass implements Serializable{ private Integer id; private Set<String> mySet; @Id @GeneratedValue
@Entity public class Person { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id; private int salary; @Version
@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class Problem { @ManyToOne private Person person; } @Entity
A typical JPA entity looks like: @Entity public class Person { @Id private int
I have written the following code: @Entity @Table(name=person) @Inheritance(strategy=InheritanceType.JOINED) public class Person { private
@Entity public class Person { @ElementCollection @CollectionTable(name = PERSON_LOCATIONS, joinColumns = @JoinColumn(name = PERSON_ID))
Suppose I have the following 2 entities: @Entity public class Person implements Serializable {
Let's say I have this entity (for Hibernate): @Entity public class Person { @Id
I have a Person and an Organisation Entity: Person looks like this: public class
@Entity public class Blobx { private String name; private BlobKey blobKey; @Id @GeneratedValue(strategy =

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.