This is a developer’s story of developing an online entity class generator. Creating an entity class for your Spring project can be easy if you have a finite number of columns in your database table. If they have more number of columns then the task becomes bit hard and can take up more time to complete creating one.
Hence I came up here with an idea of developing an online tool, which when published, can be used to get your entity classes for your database tables that you can use it directly without modification to your Spring project. The best thing about this online tool is that it is free of use, no restriction.
Also, it doesn’t need a browser extension to install! You can use it like any other simple app you can find on most of the popular websites. All you need to do is to run “table desc” query on your target database table from the database client tool to get the table description.
This description will then be given to this app through a text box to get the final entity class.
What is a table desc?
A sample “table desc” is shown below for your reference. A description of a table contains the list of columns, its attributes such as data type, column size, and information such as whether a column is unique or not and so on.
Output: Name Null Type ID Not Null INT NAME CHAR(25) CITY VARCHAR2(25)
What’s next? How to generate an entity class using Java?
The tool should get the desc query output from the user through an input text box and create an entity Java class. The should be named as the same as table name found on the desc content. The list of class member fields should be the columns present in the desc content. Data type will be appropriately be the same and nearer to the same as against each mentioned columns.
In addition to the regular data columns, a table may have an auto generated ID column marked within the content and would have a NON-NULL auto-increment label marked against such column. If such column found on the content, then the tool should add the column as a field with an annotation of “auto-generated” to it.
Please note that this implementation of special columns as a field in Java entity follows some standard as defined by their respective specifications. The tool should first initially have a common standard that most people use these days!
How useful was this post?
Click on a star to rate it!
Average rating 1.9 / 5. Vote count: 10
We are sorry that this post was not useful for you!
Let us improve this post!
Thanks for your feedback!