Posts

Showing posts with the label JPA

Data Auditing in Spring Data JPA

Image
  Many systems require auditing and tracking the change in the persistence layer. It is really helpful to investigate problems related to the data. Data auditing typically answers these questions: when was it created, who was create the record, when was it created, who modified the record last and when was it modified last.   Spring provides four annotations in the spring-data-commons module for auditing features.  @CreatedByrepresents the principal that created the entity containing the field. @CreatedDate represents the date the entity containing the field was created. @LastModifiedBy represents the principal that recently modified the entity containing the field. @LastModifiedDaterepresents the date the entity containing the field was recently modified. Besides the four mentioned annotations, Spring also provides @EnableJpaAuditing that aims enable auditing feature. In order to explain how the auditing feature works in Spring Data JPA, we should be known abou...

Using Spring REST Docs with automated tests

Image
  Spring REST docs provide a lot of features and flexibility to generate documentation for your REST APIs. One of the powers of REST docs is its ability to generate the documentation based on the unit tests which ensure that documentation is accurate, concise, and well-structured. To enable the Spring REST Docs support, add spring-restdocs-mockmvc as an additional dependency in your application.  Spring REST Docs use the test cases to generate accurate and updated documentation for the REST API. If all tests pass with no issue, it will generate a sub-folder under the target/generated-snippets with a name matching the argument passed to the document method (in our case it is itShouldReturnThreeCustomers). There will be several .adoc files. One of the limitations with the AsciiDoc doc is that it is unable to render in the browser. So AsciiDoc need to be converted into a browser-friendly format like HTML. To convert our documentation into HTML format, must be use th...

Generate the documentation at runtime when app is deployed

Image
To generate the documentation at runtime, when app is deployed you need springdoc-openapi-maven-plugin .  The aim of springdoc-openapi-maven-plugin is to generate json and yaml OpenAPI description during runtime.  If you want to get swagger definitions properly, the application should completely running as locally.  The plugin works during integration-tests phase, and generate the OpenAPI description.  The plugin works in conjunction with spring-boot-maven plugin.  You can test it during the integration tests phase using the maven command: mvn verify   In order to use this functionality, you need to add the plugin declaration on the plugins section of your pom.xml. References:  springdoc-openapi-maven-plugin

CRUD Goes Even Easier With JPABuddy

Image
Create, Read, Update and Delete are the four basic operations of persistence storage. We can say these operations collectively as an acronym CRUD. These operations can be implemented in JPA. JPA is a standard for ORM. It is an API layer that maps Java objects to the database tables.  ORM stands for Object Relational Mapping. It converts data between incompatible type systems in object-oriented programming languages.  JPA Buddy is an IntelliJ IDEA plugin that helps developers work efficiently. JPA Buddy is a tool that is supposed to become your faithful coding assistant for projects with JPA and everything related. It is an advanced plugin for IntelliJ IDEA intended to simplify and accelerate everything related to JPA and surrounding mainstream technology. In fact, you can develop an entire CRUD application or a simple microservice by spending nearly zero time writing boilerplate code. The video demonstrates the features of JPA Buddy by creating a simple CRUD application from ...