{"id":17749867,"url":"https://github.com/mat3e/less-popular-spring","last_synced_at":"2025-10-10T07:33:59.199Z","repository":{"id":84498490,"uuid":"468093370","full_name":"mat3e/less-popular-spring","owner":"mat3e","description":"Less popular Spring tricks: no Hibernate, rest repo, projections","archived":false,"fork":false,"pushed_at":"2024-04-17T16:22:39.000Z","size":255,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T07:33:31.369Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mat3e.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-09T21:11:34.000Z","updated_at":"2024-04-12T23:07:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"07b1bb5e-53e6-4136-bf94-79501b9d164e","html_url":"https://github.com/mat3e/less-popular-spring","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mat3e/less-popular-spring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mat3e%2Fless-popular-spring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mat3e%2Fless-popular-spring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mat3e%2Fless-popular-spring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mat3e%2Fless-popular-spring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mat3e","download_url":"https://codeload.github.com/mat3e/less-popular-spring/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mat3e%2Fless-popular-spring/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003192,"owners_count":26083533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-26T11:25:16.447Z","updated_at":"2025-10-10T07:33:59.167Z","avatar_url":"https://github.com/mat3e.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Less popular Spring tricks: no Hibernate, rest repo, projections\n\nTypical Spring project\n\n* JPA (usually Hibernate ORM), `@Entity` classes here and there, Flyway for DB migrations\n* Spring Data - SQL for above classes; especially `JpaRepository`\n* Entity-DTO mapping, usually done by hand\n* `@Controller` or `@RestController` exposing DTOs\n\nThis project\n\n* Still with Flyway\n* Still with Spring Data\n* No JPA, no \"manual\" mappings, fancy REST (HATEOAS)\n\n## Example code\n\nPerfect catalog-like CRUD application. The main (and only) entity is called `Category` and thanks\nto [carwarninglights.net](https://carwarninglights.net/car-guide/car-segments/) I made it displaying car segments.\n\nFrom the first view it looks typical - there is a file-based H2 SQL database, it can be started easily and\nwith `src/main/resources/Less popular Spring tricks.postman_collection.json` anyone can\nuse [Postman](https://www.postman.com/) to check it in action.\n\nHowever, code itself can be a little confusing. There is no JPA, no Spring Data JPA dependency, you cannot extend a\ntypical `JpaRepository`. There are way more interfaces than classes and a familiarly looking `TraditionalController`\ndoesn't seem to be used much. And git commits show it was built like that from the very beginning!\n\n## No Hibernate\n\n⚠️ Disclaimer ⚠️\n\u003e After working a year with Spring Data JDBC within the actual project, I liked it, but it's meant for the \"command\" part of the system and it's not a perfect choice for \"query\" (heavy reading). E.g. no way to prevent N+1 selects problem. I go with Spring Data JDBC in command and with `JdbcTemplate` in query parts of systems.\n\nDo you know we don't need Hibernate to use `@Table` annotation?\n\n[![Spring Data JDBC comment](./jdbc.png)](https://betterprogramming.pub/which-java-microservice-framework-should-you-choose-in-2020-4e306a478e58)\n\n### [Spring Data JDBC](https://spring.io/projects/spring-data-jdbc)\n\n`org.springframework.data.annotation` and `org.springframework.data.relational.core.mapping` to the rescue!\n\n[Detailed documentation](https://docs.spring.io/spring-data/jdbc/docs/current/reference/html/#reference).\n\n## Rest Repo\n\n⚠️ Disclaimer ⚠️\n\u003e I'd personally use Rest Repositories just for read operations. Preferably built on top of the pure `Repository` interface. It can be a powerful thing for \"query\" part of the system, especially combined with projections. However, in practice it seems sooner or later you'd move towards a traditional approach which is more customizable than `@RepositoryRestResource` and `@RestResource` options, default interface methods and even `RepositoryRestController`.\n\n[Spring Data REST](https://spring.io/projects/spring-data-rest) specifically. With\nits [detailed documentation](https://docs.spring.io/spring-data/rest/docs/current/reference/html/#reference).\n\n## Projections\n\n⚠️ Disclaimer ⚠️\n\u003e I really like projections. In my eyes it's an easy opt-in solution which can be replaced with a hidden implementing class and `ObjectMapper` configs if needed.\n\nNot only\nfor [above repositories](https://docs.spring.io/spring-data/rest/docs/current/reference/html/#projections-excerpts), but\nalso with a more \"traditional\" approach:\n\n```java\n//                                                 👇\ninterface CategoryRepository extends Repository\u003cCategory, Long\u003e {\n\n    //        👇\n    List\u003cTextCategoryVM\u003e findTextualCategoriesBy();\n}\n\n@Getter\n@NoArgsConstructor(access = PROTECTED)\n@Table(\"categories\")\nclass Category {\n\n    @Id\n    private Long id;\n    @NotBlank\n    private String code;\n    @NotBlank\n    private String name;\n    private String description;\n    private String imageUrl;\n    @Column(\"is_deprecated\")\n    private boolean deprecated;\n}\n\n// getters \"compatible\" with the Category class\ninterface TextCategoryVM {\n\n    String getCode();\n\n    String getName();\n\n    String getDescription();\n}\n```\n\nFurther read:\n\n* Baeldung: [Spring Data JPA Projections](https://www.baeldung.com/spring-data-jpa-projections)\n* [Generic `findBy(Class\u003cT\u003e type)` projection](https://stackoverflow.com/questions/48441324/spring-data-jpa-generic-projection-findall)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmat3e%2Fless-popular-spring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmat3e%2Fless-popular-spring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmat3e%2Fless-popular-spring/lists"}