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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:12:27+00:00 2026-05-26T00:12:27+00:00

I have two entities Task and TaskStatus. A task can have a history of

  • 0

I have two entities Task and TaskStatus. A task can have a history of TaskStatuses (1-n). I listed them below (stripped down to remove clutter).

@Entity
public class Task implements Serializable {
    @Id
    private int task_id;
    private String name;
    private String description;

    @JsonManagedReference("task-taskstatuses")
    @OneToMany(fetch = FetchType.LAZY, mappedBy="task")
    private Collection<TaskStatus> task statuses;

    @Transient private String latest_status; // this field I want to calculate based on the task statuses
}


@Entity
@IdClass(TaskStatusId.class)
public class TaskStatus implements Serializable {
    @Id
    @ManyToOne
    @JoinColumn(name="task_id", referencedColumnName="task_id")
    private Task task;
    @Id
    private Timestamp timestamp;
    private String status;
    private String username;
}

The question is about the field latest_status in the Task entity. I have a web service that offers a REST interface (based on Jersey, Jackson and Tomcat). There is a simple /RetrieveTask.json REST URI that returns a serialized Task object, and that works perfectly. But now I wanted to add a field to the Task entity that indicates the latest status of the Task (which can be determined by the TaskStatus table sorted on the field timestamp). What is the best way to do that?

I though it should be a Transient field, because I did not seem to make sense to store it in the Task table in the database. Should I calculate that Transient field latest_status in the JPA service method and fill the field in there using a JP QL query?

  • 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-26T00:12:28+00:00Added an answer on May 26, 2026 at 12:12 am

    Entities may have methods:

    public String getLatestStatus() {
        // sort a copy of the list of task status by timestamp
        // return the status of the last element of the copy of the list
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities. Groups. Pools. A Group can create many pools. So I
I have two entities, EntityA and EntityB. EntityB can optionally be related to EntityA,
I currently have two entities in LLBLGen and would like to merge them together
Imagine you have two entities, Player and Team , where players can be on
I have two entities, Account and Subscription with a many-to-many association between them. I
I have two entities with many-to-many relationship defined on them. <set name=TreasuryCodes table=ServiceProviderAccountTreasuryCode lazy=true
I have two entities Group and Contact. A contact can belong to many groups,
I have two entities User and Course. A user can take several courses which
I have two entities one is Event and another is User. User can like
I have two entities, Users and Books with a has_and_belongs_to_many relationship. How can I

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.