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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:09:55+00:00 2026-05-28T11:09:55+00:00

Here’s my use case : public class User extends Model {} public class TableA

  • 0

Here’s my use case :

public class User extends Model {}

public class TableA extends Model {
    @OneToMany
    public List<TableB> tableBs;

    @ManyToOne
    public AnObject anObject;
}

public class TableB extends Model {
    @ManyToOne
    public TableA tableA;

    @ManyToOne
    public User user;

    public String status;
}

The user get a list of TableA entries based on an instance of AnObject. I’d like to show this user if TableA is new or not.

(note that TableB is acting like a n:n table for User and TableA, I can’t integrate it to TableA)

To say if it is new, it depends on TableB. For that, I have two options :

  • Either creating TableB when I create TableA, but with the status at NEW or No
  • Or not creating TableB for that user. If the link is missing for that user, that mean it’s new. (doing it, I could remove the column status)

(actions depends on “new”, it’s not just a label to show).

Now, in my JPA request, how can I indicate if, for that member, TableA entry is new or not ?

The simple way would be to get the list of TableA, and then go through the List to check if there is the User in it (a method like isUserInTableB(User user))

But is it possible to do it with JPA, for example by having only one item in the List, that would be the User, or empty if this user is not linked ?

(I hope I’m clear, it’s not so much in my head :/)

Thank you really much for your help, I appreciate!

  • 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-28T11:09:56+00:00Added an answer on May 28, 2026 at 11:09 am

    The tableBs list is an attribute not a result of a query so you can’t load it partially.

    What you can do with one query is retrieve the tableB instance based on the tableA instance and the user instance. Something like

    public static TableB findByTableAAndUser(TableA, tableA, User user) {
        return find("select tableB from TableB tableB where tableB.tableA=? and tableB.user=?", tableA, user).first();
    }
    

    Another way, if you want to have an “isNew” method on a tableA instance is to fetch the tableBs collection when you load tableA and juste iterate through tableBs instances in the isNew method. Something like

    public boolean isNew(User user) {
        for (TableB tableB : tableBs) {
            if (tableB.user.equals(user)) {
                return true;
            }
        }
        return false;
    }
    

    your findByIdWithTableBs method could be

    public static TableA findByIdWithTableBs(Long id) {
        return find("select tableA from TableA tableA fetch join tableA.tableBs where tableA.id=?", id).first();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
here is the site : http://www.notrepanorama.com at the bottom left, i use a jquery
Here is what I want to do. Use this HTML line and have the
Here is what is supposed to happen: The moment the user chooses an option
Here an example of my checkbox list http://jsfiddle.net/YnM2f/ Let's say I check on G
Here's the flow that I am trying to achieve: 1) User uploads an audio
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here a simple question : What do you think of code which use try
Here is my problem...I have a page that loads a list of clients and
here is the scenario 1: user starts to type some word, autocomplete engine shows

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.