0

I'm looking for a way to generate a class from database values, in order to provide an updated builder class using the latest values available. The use case is this:

With a table that looks like this

id ref_type
1 name
2 status
3 address

I am hoping to generate a builder class that can be used like this

new ClassBuilder()
  .setName(name)
  .setStatus(status)
  .setAddress(address)
  .build();

The goal is to be able to generate an updated builder class whenever values are added to the database table (using Liquibase). Is anyone aware of any libraries that can help with this, or a strategy for doing this from scratch? Our projects are mostly Java 11, with Groovy and Spring Boot.

2
  • Take a look at this Commented May 25, 2022 at 15:36
  • This would be helpful to generate a class based on the database schema, but I'm hoping to generate the class based on the table content. Commented May 25, 2022 at 15:38

1 Answer 1

0

You could try Reverse Engineering from Hibernate Tools. It generates domain classes from the database schema.

But, i dont think it supports building your instances too. Though, this would be trivial if you have proper setters on the domain class.

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

2 Comments

I'd like to generate the builder from the database content, not from the schema. The generator will need to first make a connection to the database, fetch all values from the appropriate table, and then build the class based on the results.
The class definition must be generated from the database schema because basically it needs to map column types (of each table) to member types (of the class). After the class is defined, you can create instances from each one of the table rows.

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.