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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:54:05+00:00 2026-06-17T05:54:05+00:00

I have two entities Issue and Issue_Tracker . Issue.java: public class Issue implements Serializable

  • 0

I have two entities Issue and Issue_Tracker.

Issue.java:

public class Issue implements Serializable
        {
        private Integer issue_id;
        private String  issue_description;
        private Date issue_raised_date;
        private Set<Issue_Tracker> issueTracker = new HashSet<Issue_Tracker>(0);



        @OneToMany(fetch=FetchType.LAZY, mappedBy="issue_id")
        public Set<Issue_Tracker> getIssueTracker() {
        return issueTracker;
    }

        public void setIssueTracker(Set<Issue_Tracker> issueTracker) {
        this.issueTracker = issueTracker;

Issue_Tracker.java:

public class Issue_Tracker implements Serializable
{  
     private Integer   issue_id;
     private String    tracker_status;
     private Timestamp tracked_time;

when i left join both the table and i get following data as follows using query:

SELECT issues.issue_id,
       issues.issue_description,
       issue_tracker.tracker_status,
       issue_tracker.tracked_time
FROM issues
     LEFT JOIN issue_tracker on issues.issue_id = issue_tracker.issue_id 
     WHERE issues.status = "Escalate To"

and output is

  issue_id  tracker_status      tracked_time
    123     Assigned           1/8/2013 11:44   //1st entry
    123     Assigned           1/9/2013 11:45
    123     Completed          1/10/2013 12:52  // last entry

    32      Assigned           1/9/2013 16:46   //1st entry

    32      Assigned           1/10/2013 18:46  //last entry

    33      Assigned           1/9/2013 16:47   //1st entry

    33      Cancel             1/9/2013 17:49  //last entry

Now when i did these join using criteria, I get these results

      issue_id  tracker_status      tracked_time
        123     Assigned           1/8/2013 11:44 //1st entry of issue_id 123
        32      Assigned           1/9/2013 16:46
        33      Assigned           1/9/2013 16:47

using following criteria

         Criteria criteria = session.createCriteria(Issue.class);
         criteria.setFirstResult(from);
         criteria.setMaxResults(size);
         criteria.setFetchMode("Issue.issueTracker",FetchMode.JOIN);
         criteria.add(Restrictions.eq("status", "Escalate To"));

Now expected output is

      issue_id  tracker_status      tracked_time
        123     Completed          1/10/2013 12:52 // last entry
        32      Assigned           1/10/2013 18:46 //last entry
        33      Cancel             1/9/2013 17:49  //last entry

How to achieve this, I am stuck here since last three days, any help would be great, is it happening because of this line where i am trying one to many mapping

private Set<Issue_Tracker> issueTracker = new HashSet<Issue_Tracker>(0);

because a Set does not allow duplicate values, if so what would be the possible approach.

  • 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-17T05:54:06+00:00Added an answer on June 17, 2026 at 5:54 am

    Try this:

    SELECT i.issue_id, i.issue_description,
           it.tracker_status, it.tracked_time
    FROM issues i 
    LEFT JOIN ( SELECT it.issue_id, it.tracker_status, it.tracked_time 
                FROM issue_tracker it 
                INNER JOIN (SELECT issue_id, MAX(tracked_time) tracked_time 
                            FROM issue_tracker GROUP BY issue_id
                           ) A ON it.issue_id = A.issue_id AND it.tracked_time = A.tracked_time 
              ) it ON i.issue_id = it.issue_id 
    WHERE i.status = "Escalate To";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities A and B. public class A{ @Id @GeneratedValue private Integer
I have two entities: Recipe and Ingredient. Entites: public class Ingredient { public int
I have two entities like this: public class Service { public virtual int ServiceId
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
I have two entities: public class Parent() { public ICollection<Child> Children { get; set;
I have two entities, a Shelf and a Product : public class Shelf {
I have two entities Issue and Issue_Tracker . I have joined both table in
I have two entities Visita and Cliente that implements respectively two interfaces IVisita and
I have two entities. Price class has CalculableValue stored as SortedMap field. In order
I have two entities which are Student and Class entities. Student and Class are

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.