LFMS - Database Calls Trade

Participants:

Issues:

  • In order to get data from the database, we use Hibernate which maps Java classes to database tables. It is generally light-weighted, but making duplicate calls can potentially slow down the application. 
  • It is not an issue at the moment since the application is fairly simple. However, if we later add functionalities that may require querying data from more than two to three database tables, the application may take longer to load
  • The issue may not even be noticeable to the users, but it is better to address this potential issue now since fixing it later would be very difficult

Winner:

1) Create Data Transfer Objects (DTOs)

Options:

  1. Create Data Transfer Objects (DTOs)
    1. Pros
      1. Reduce the amount of calls to the database
      2. Persistent - prevent update calls in multiple locations which can cause unintended overrides since every direct interaction to the database will be in the Service tier
      3. Guarantee that API calls retrieve consistent data across the software - but chances of inconsistent data is very low because Hibernate handles that
    2. Cons
      1. Harder to maintain because you have to update both the DTO and the entity class to keep the mapping up-to-date
      2. Will need to do additional mapping and error handlings, which may not be worth the effort because the project is on a smaller scale

  2. Ignore the Issue
    1. Pros
      1. Much simpler code
      2. If the issue ever becomes noticeable, we can just throw a spinner on the screen to let the user know that the page is loading
    2. Cons
      1. Somewhat inefficient :(
      2. Very unlikely because of the scale of the project, but if not designed well, it can cause data inconsistency 

  3. Get Rid of Hibernate 
    1. Pros
      1. None - I'm just putting this option here to fangirl about why auto-mapping makes life so much easier and we should never get rid of Hibernate
    2. Cons
      1. Every time you make a PUT request, you have to individually map every variable to its corresponding column in a table
      2. Hibernate has so many built-in methods so unless you need to join two or more tables together so you can avoid SQL queries. Removing it would mean higher of risks of making mistakes and getting incorrect data
      3. When you retrieve multiple rows from the database, Hibernate will just magically make them all objects stored in a Collection for you. You'll have to individually map them and do wacky conversion
      4. Data retention can get tricky
Drop here!
Drop here!