Automatically add `insertable = false, updatable = false` to objects created using NetBeans

I am working on a Java EE project using Netbeans. I automatically created JPA entities and controllers using the database.

I want to update the database by adding more tables or updating existing ones. The problem I am facing is that I need to regenerate all JPA entities and controllers that I don't want, since most of my objects are modified to include

insertable = false, updatable = false 

in @Column where the database uses current_timestamp . If I regenerate them, I will have to change all entities again by including insertable = false, updatable = false .

This is what I am trying to achieve after creation.

 @Column(name = "CREATED_ON", insertable = false, updatable = false) @Temporal(TemporalType.TIMESTAMP) private Date createdOn; 
+5
source share
1 answer

You need to do this in 2 steps, at each step you can select objects to create, and if you select them correctly, you will not write on top of existing classes:

  • Creating Entities from the Database
  • Generate controllers from entity classes

When I create entities from existing tables, you choose which tables you want to create. Just do it and don’t choose existing ones. Right-click the project and select New-> other-> Persistence (category) β†’ Entity Classes From Database . I get the following dialog:

enter image description here

Then do the same except select the JPA controller classes from the entity classes

0
source

Source: https://habr.com/ru/post/1238882/


All Articles