Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the specific columns in table #120

Open
mzgg opened this issue Jun 23, 2020 · 3 comments
Open

How to get the specific columns in table #120

mzgg opened this issue Jun 23, 2020 · 3 comments
Labels

Comments

@mzgg
Copy link

mzgg commented Jun 23, 2020

Hello,
I have entity that is have many relational field. I want show to 2 column in frontend, but findAll methods is getting all columns, I don't want execute the joining their relational table

@darrachequesne
Copy link
Owner

darrachequesne commented Jun 24, 2020

Hi! I think the easiest way is to create another entity, with only necessary fields:

@Entity
public class UserSummary {
  private String id;
  private String name;
}

And to search on this entity, instead of the full User.

@MariumHashmiBM
Copy link

Hi! I think the easiest way is to create another entity, with only necessary fields:

@Entity
public class UserSummary {
  private String id;
  private String name;
}

And to search on this entity, instead of the full User.

Hello, this is definitely a neat approach but can you suggest in case we need the dynamic columns from query at runtime
Meaning, we only know the columns at runtime to be fetched. In this case creating another entity is not an option
Can we use criteriaQuery.multiselect with the rest of you plugin? Because this is very well made plugin, just need to add this specific requirement.

Thanks in advance

@darrachequesne
Copy link
Owner

@MariumHashmiBM That's a good question! I'm not sure that's feasible with criteriaQuery.multiselect, as it requires that the entity provides a constructor with the selected fields. Also, I don't think @Transient annotations can be added at runtime.

I'm open to suggestion on this, if you find anything.

Note: the logic for the creation of the specification is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants