0

I want to connect to a database with lot of tables with Java Spring MVC.

Currently, I am coding one class for each table. Ex;

@Table(name = "sa_user") //table name

public class SaUser implements Serializable {

private static long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "sa_user_id")
private Integer saUserId; 
...
...

}

Do I have to write these class for all of the tables. This is a huge task. What is the best way?

Muditha C
  • 1
  • 1

1 Answers1

0

There are some utilities which ease the task of creating the Entities whiche represent the database tables.

I usually use one called MinuteProject, which is a small java desktop app which opens a kind of assistant to connect to the database and generates all the Entities representing the database Tables, even including relationships, foreign keys, etc... between them.

I have been using it for more than acouple of years already and I feel comfortable with it. This is a screenshot of it's main view:

enter image description here

There is a way of doing it from eclipse too, though I have never used it:

https://www.eclipse.org/webtools/dali/docs/3.2/user_guide/tasks006.htm

jlumietu
  • 6,234
  • 3
  • 22
  • 31
  • Thank you for the answer. I am using NetBeans IDE. Do you know any plugin for it. – Muditha C Oct 23 '17 at 11:29
  • I have not used NetBeans for so many years, but I've just found some info googling https://netbeans.org/kb/docs/javaee/ecommerce/entity-session.html – jlumietu Oct 23 '17 at 11:36
  • HibernateTools also do same thing. check this for more detail and usage : [link](http://o7planning.org/en/10125/using-hibernate-tools-generate-entity-classes-from-tables) – Habil Oct 24 '17 at 08:41