Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to generate entity classes with MySQL request? #21

Open
MarErm27 opened this issue Jun 17, 2020 · 6 comments
Open

How to generate entity classes with MySQL request? #21

MarErm27 opened this issue Jun 17, 2020 · 6 comments
Labels

Comments

@MarErm27
Copy link

MarErm27 commented Jun 17, 2020

Hello, here is a MySQL script below. Can Telesys-cli create classes with Hibernate annotations based on this script? How to launch it during the build of the Java Maven project?

CREATE TABLE IF NOT EXISTS orders (
    order_id INT PRIMARY KEY,
    order_number VARCHAR(128),
    order_data  VARCHAR(4096),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)ENGINE=INNODB;

CREATE TABLE IF NOT EXISTS invoices (
	invoice_id INT PRIMARY KEY,
        order_id INT UNIQUE,
	INDEX ord_id (order_id),
        FOREIGN KEY (order_id)
		REFERENCES orders(order_id)
                ON DELETE CASCADE,    
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at  TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)ENGINE=INNODB;
@l-gu l-gu added the question label Jun 18, 2020
@l-gu
Copy link
Member

l-gu commented Jun 18, 2020

Telosys can do that from the database tables created by this script but not from the script itself (you need a database to create a "db model").
See this wiki page for "Db Model" creation : https://github.com/telosys-tools-bricks/telosys-cli/wiki/Guide-Step-2-DB-Model
Once the "db model" is created just use JPA templates to generate the annotated entities (and more if you want : API, screens, JUnit tests, etc)

Telosys has been thought to replace the developer, therefore it positions itself before the compilation/build phase. Moreover Telosys is usable to generate any kind of languages (not only Java). So, there's no Maven plugin.

@MarErm27
Copy link
Author

Can I add Telosys-cli as a library from my project and to configure it from Java code? Can I find it in Maven?

@l-gu
Copy link
Member

l-gu commented Jun 18, 2020

Telosys is not published on Maven central but you can just add the JAR "telosys-cli-3.X.X-xxx.jar" in you project libs. It's a "fat jar" and it contains everything you need (including Telosys-API).

@MarErm27
Copy link
Author

I was wondering if I can ask for an example that uses this "jar" to automatically create the dm model and classes from MySQL?

@l-gu
Copy link
Member

l-gu commented Jun 18, 2020

The best example is probably the "new db model" command in Telosys-CLI itself.
See https://github.com/telosys-tools-bricks/telosys-cli/blob/master/src/main/java/org/telosys/tools/cli/commands/NewDbModelCommand.java

@MarErm27
Copy link
Author

I added the jar file to the libraries folder
image

and added this class
image

How to get the missing dependencies?
And what do I do next? Call the newDatabaseModel(Integer id) method? What is id?

How do I specify that I need the entities to appear at com.qbwc.db.entities package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants