[JAVA] I want to stop snake case in table definition

What is a snake case?

In table definition, it is often defined by snake case (\ _ delimited). For example, an example of a master that stores user information will be described. Table name: mst \ _user

Logical name Physical name
User ID user_id
username user_name

Relationship with application development

Application development languages are often not snake cases. For example, in the case of java, it may be Pascal case and Camel case.

What's wrong

Taking java as an example, the class (DTO) corresponding to mst_user is as follows according to the Java convention (Pascal case, camel case).

public class MstUser {
    private String userId;
    private String userName;

    // getter,setter omitted
}

Although the table is a snake case, mapping is required because the java convention is different. There are some problems associated with this.

  1. The burden of creating specifications is heavy Example) Wrong when creating API specifications. Since there are usually many items, it is easy to make a mistake by copying the items from the table definition and replacing the snake case with camel case. user_id => userid => I made a mistake! In particular, when only designing and requesting development to the outside, a Q & A such as "What about userId?"

  2. It is troublesome if you make a mapping mistake during development Since SQL is a snake case, it is necessary to describe the mapping to java class. If it can be automatically generated by the OR mapper, if it is a specification that joins, the mapping will be written steadily, so there is a possibility of making a mistake. The value acquisition result is null => It happens that there was a mapping error.

  3. Mutual conversion between snake case and camel case is troublesome Although it is related to 1 and 2, it takes a lot of time and effort to convert snake case => camel case and camel case => snake case when mapping. It may be a little better if you make a tool, but it is still a hassle.

Stop snakecase and adapt to development language conventions

Follow the java conventions.

Table name: MstUser

Logical name Physical name
User ID userId
username userName

DTO

public class MstUser {
    private String userId;
    private String userName;

    // getter,setter omitted
}

This will save you the trouble of mapping, so you can design and develop efficiently. Are there any disadvantages?

Table of Contents

Recommended Posts

I want to stop snake case in table definition
I want to stop Java updates altogether
I want to use @Autowired in Servlet
I want to use arrow notation in Ruby
I want to pass APP_HOME to logback in Gradle
rsync4j --I want to touch rsync in Java.
I tried to output multiplication table in Java
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
I want to get the value in Ruby
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
I want to use fish shell in Laradock too! !!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to use a little icon in Rails
I want to define a function in Rails Console
I want to click a GoogleMap pin in RSpec
I want to convert characters ...
I want to find a relative path in a situation using Path
I want to set the conditions to be displayed in collection_check_boxes
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to create a Parquet file even in Ruby
I want to transition to the same screen in the saved state
[Ruby] I want to reverse the order of the hash table
I want to simplify the conditional if-else statement in Java
Swift: I want to chain arrays
I want to use FormObject well
[Ruby] I want to put an array in a variable. I want to convert to an array
I want to convert InputStream to String
I want to get some properties as JSON strings in Jackson!
I want to docker-compose up Next.js!
I want to display the images under assets/images in the production environment
I want to add devise in Rails, but I can't bundle install
I want to remove the top margin in Grouped UITableView (swift)
[Java] I want to perform distinct with the key in the object
I want to change the value of Attribute in Selenium of Ruby
Want to throw an IOException out of Stream? in that case
[Android] I want to get the listener from the button in ListView
[Ruby] I want to output only the odd-numbered characters in the character string
[Rails] I want to send data of different models in a form
I want to write JSP in Emacs more easily than the default.
I want to select multiple items with a custom layout in Dialog
I got stuck using snake case for variable name in Spring Boot
(Limited to Java 7 or later) I want you to compare objects in Objects.equals
[Ruby] I want to display posted items in order of newest date
I want to display a PDF in Chinese (Korean) with thin reports
My memorandum that I want to make ValidationMessages.properties UTF8 in Spring Boot
I want to get the IP address when connecting to Wi-Fi in Java
I want to display an error message when registering in the database
I want to ForEach an array with a Lambda expression in Java
[Java Spring MVC] I want to use DI in my own class
"Teacher, I want to implement a login function in Spring" ① Hello World
I want to develop a web application!
I want to write a nice build.gradle
I want to eliminate duplicate error messages
I want to make an ios.android app
I want to display background-ground-image on heroku.
I want to use DBViewer with Eclipse 2018-12! !!
I want to RSpec even at Jest!
I want to write a unit test!
I want to target static fields to @Autowired