A view in to your data

In the Domino world the data store is part of the application container. When building your app you will invariably start by creating your forms and views to hold the basic structure of the data. For this Spring Boot based application I am going to start with the same step of building my data.

Two of the dependencies that I selected from the Spring Boot Initializer were spring-boot-starter-data-jpa and com.h2database. You can see these in your pom.xml file in the root of your project structure. The H2 Database is an in-memory or file based SQL data source. It is perfect for development work but should be replaced in a production environment. The spring-boot-starter-data-jpa dependency adds in a data persistence layer based on Hibernate.

For the application I am going to need Locations and People. I’m going to create a new package under com.qtzar called ‘model’ and then create a java class in there called Location.

First I need to annotate the class with the @Entity annotation. This will indicate to Hibernate that the class represents a data structure which will then translate to a table in my data source.

Next we add all the columns to the table. This is done by adding private fields to the class. You will also notice that the first field has been annotated with @Id. This indicates to Hibernate that the field called id is the unique key for the table.

Next we need a constructor for the class. I have created two constructors. One is an empty constructor and one takes a list of parameters that match up to all the fields in the class. This allows me to create a blank location or a fully constructed location.

Then you will need a getter and a setter for each field you added to the class. You COULD type them all out by hand but that would be painful so why not use your IDE to do the job for you. IntelliJ and Eclipse both have code generators that you can use for create getters and setters.

Another option would be to investigate Project Lombok. Then you just need to add @Getter and @Setter to the class annotations and as long as Project Lombok is setup correctly the getters and setters will be auto generated in the compiled code.

Advertisements
Tagged with: , , , , ,
Posted in Domino To Spring, None
One comment on “A view in to your data
  1. David Marko says:

    Just for Lombok, we have had more problems with this than it solved. Currently we are ussing SpringBoot + Vaadin + MongoDB + Elasticsearch and Kotlin language is great and stable option here (with great support in IntelliJ as it comes from Jetbrains as well). For your case see data classes here http://kotlinlang.org/docs/reference/data-classes.html

    Like

Comments are closed.

Archives
%d bloggers like this: