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

Introduce the Specification<T> interface for find() and findOrCreate() #809

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

arteymix
Copy link
Member

@arteymix arteymix commented Aug 25, 2023

We have methods in BaseDao that expects a template of an entity as input and attempt to find a persistent entity in the database that satisfy some kind of business key. However, with the find(T) signature, this is unclear. We replace those by a find(Specification<T>) signature.

This will allow us in the future to cleanup BusinessKey by having some kind of standard way of generating HQL clauses and Criterions.

@arteymix arteymix added this to the 1.31.0 milestone Aug 25, 2023
@arteymix arteymix added enhancement Enhance the code or user experience cleanup Code reorganization and changes that should not impact functionality labels Aug 25, 2023
@arteymix
Copy link
Member Author

arteymix commented Sep 29, 2023

It would be nice to have implementations of Specification to fetch entities by ID and business key.

  • Specifications.byId(Long)
  • Specifications.byBusinessKey(T)
  • Specifications.byIdentifiable() would become ID if non-null else some business key

Find or create expects a little more than an ID/business key, we could have a special sub-interface for supplying a template object to create if not found.

interface SpecificationWithTemplate<T> extends Specification<T> {
    T createEntity();
}

Specification.byIdentifiable() would return a SpecificationWithTemplate where the template is the passed identifiable.

Hibernate has support for defining natural ID which are essentially business key. We could move all the BusinessKey declarations in the model declaration and use natural ID under the hood for business key-based specification.

@arteymix
Copy link
Member Author

To be valid, a specification must have either an ID or a complete business key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code reorganization and changes that should not impact functionality enhancement Enhance the code or user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant