This link How to generate persistence mapping by database schema during build of the project? described a way to generate persistence mapping by database schema - automatically creating entity classes for Hibernate.
I've followed the instructions and proceed this with settings: The result of this was different from expected. The table was created in MySQL with this script:
CREATE TABLE IF NOT EXISTS orders(
order_id INT PRIMARY KEY,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
After mapping, it didn't add the @CreationTimestamp and @UpdateTimestamp annotations to fields created_at and updated_at. How to make it to be able to create these annotations?
You can try using scripted extensions to Generate a Java POJO entity class for the selected table in Project tool window. In the dialog that opens, specify the directory in which the .java class file should be generated. Please see attached screenshot. You can customize the script to generate any text. See also these examples and Generate simple classes from database objects in DataGrip blog post.