telosys-cli
telosys-cli copied to clipboard
How to generate entity classes with MySQL request?
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;
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.
Can I add Telosys-cli as a library from my project and to configure it from Java code? Can I find it in Maven?
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).
I was wondering if I can ask for an example that uses this "jar" to automatically create the dm model and classes from MySQL?
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
I added the jar file to the libraries folder
and added this class
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?