Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a Java Class from a database for use with Hibernate 4

I want to use Hibernate 4 to work with the database. I use this configuration to map tables in database with Java class:

<mapping class="test.table1"></mapping>

In my Java class I define compatible fields with the table. But now I want to generate the compatible fields automatically. Is there any tool to do it?

I'm using Java 1.7 and MySQL.

like image 212
Minh Le Avatar asked Sep 06 '25 22:09

Minh Le


1 Answers

If you just want to generate some Java classes based on the schema defined in your database why don’t you use a code generator designed for this kind of job?

For example you could use Telosys, it’s a very handy tool that can create a “database model” in a few minutes by connecting to an relational DB and then use it to generate any kind of code and especially Java classes.

The advantage is that you can adapt the templates if necessary (and if you want you can generate more than the domain classes).

For more information see the web site http://www.telosys.org/ and read this article https://modeling-languages.com/telosys-tools-the-concept-of-lightweight-model-for-code-generation/

like image 181
rlopez Avatar answered Sep 10 '25 00:09

rlopez