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.

5
  • 1
    Fixed the code formatting (4 space) and cleaned up the grammar. However, you probably need to provide more detail about your environment (which database are you using?) and explain a bit more what you are trying to accomplish. If you've tried something already, what was insufficient or broken? Commented Mar 5, 2015 at 17:45
  • I'm using java 1.7 and MySQL Commented Mar 5, 2015 at 18:06
  • Tidy up grammar and add the MySQL tag as it might be important. However, we still need to see more of your code to help you with your situation. Commented Mar 5, 2015 at 18:22
  • Do you want generate a Java class from a Db table, or the inverse, generate a Db table from a Java class entity? Commented Mar 5, 2015 at 20:30
  • 1
    I want to generate java Class form Data Base Commented Mar 7, 2015 at 3:56

2 Answers 2

2

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/

Sign up to request clarification or add additional context in comments.

Comments

1

You can use Hibernate Tools Reverse Engineer, which inspects the database and generates the domain model classes from the database table definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.