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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:55:37+00:00 2026-05-11T00:55:37+00:00

Following class structure is given: class Job { String description; Collection<JobHistory> history; } class

  • 0

Following class structure is given:

class Job  {     String description;     Collection<JobHistory> history; }  class JobHistory {     Date assignDate;     User jobOwner; }  class JobOwner  {     String name;     String id; } 

This class-structure is accessible on the db via JPA. In the DAO-Layer I can write queries in JPA syntax.

The Problem: I want a list with Job and JobHistory entries for a given owner with given id and who is the last one in the Jobhistory of the job (ordered by assignDate). Sounds quite complicated, perhaps simpler: give me all jobs and JobHistory where specified owner is the actual owner of the job.

Update: for clarity I will slightly change the names of the classes.

class Job  {     String description;     Collection<JobOwnerHistory> history; }  class JobOwnerHistory {     Date assignDate;     User jobOwner; }  class JobOwner  {     String name;     String id; } 

Every Job has a history of his owners sorted by assignDate. The actual owner got the job last assigned (i.e. MAX(assignDate)). I want find for every job the JobOwnerHistory entry with MAX(assignDate) for a specific user User.

  • 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. 2026-05-11T00:55:38+00:00Added an answer on May 11, 2026 at 12:55 am

    Try:

    SELECT j, j.history FROM Job j JOIN User u WHERE u.name = :name 

    If I were to do this in EclipseLink, I would change it slightly:

    public List<Job> getAllJobsForUser(String username) {   List<Job> jobs = entityManager     .createQuery('SELECT j FROM Job j JOIN User u WHERE u.name = :name')     .setParameter('name', username)     .setHint(QueryHints.BATCH, 'j.history')     .queryForList(); } 

    The difference? In the first version, you’re returning two objects, so you have to retrieve them from a List or Object arrays whereas in the second, the query hint just loads all the job histories from an (assumedly) lazyy one-to-many relationship.

    I don’t know if Hibernate has an equivalent to this. Toplink Essentials doesn’t. But it’s one of my favourite features of EclipseLink.

    Oh and obviously you can (and probably should) use a named query instead of an adhoc query like I’ve done (since those can be verified during the build).

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you set up wildcard mapping on the server that… May 12, 2026 at 1:04 am
  • Editorial Team
    Editorial Team added an answer I would suggest that rather looking for an active or… May 12, 2026 at 1:04 am
  • Editorial Team
    Editorial Team added an answer As with every other "what's the best" question in the… May 12, 2026 at 1:03 am

Related Questions

Let's say I have the following class structure: class Car; class FooCar : public
This same question was asked here and an answer was given which is workable,
I'm using JDK 1.4...so I don't have access to the nice concurrency stuff in
Lasty, I tried to implements an hybrid structure in Java, something that looks like:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.