5

I am working on a Java EE project using Netbeans. I automatically generated the Entities and JPA Controllers using the database.

I want to now update the Database by adding more tables or updating existing ones. Problem I run into is that I have to re-generate all the Entities and JPA Controllers -- which I do not wish to as most of my entities are modified to include

insertable = false, updatable = false

in the @Column where the database uses current_timestamp. If I regenerate them, I'll have to modify all the entities again to include the 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;
myselfmiqdad
  • 2,518
  • 2
  • 18
  • 33
  • Usually, setting the Hibernate's property `hibernate.hbm2ddl.auto` to **update** should only update your schema where changes are detected, so it should solve your problem. Can you try this approach? – Bonifacio Dec 28 '15 at 15:55
  • I am unable to find that property in my project – myselfmiqdad Dec 31 '15 at 00:58
  • If so, please include the following line in your **persistence.xml** file: `` – Bonifacio Jan 02 '16 at 23:46

1 Answers1

0

You need to do it in 2 steps, at each step you can select the objects to create from and if you select them properly you won't write over your existing classes:

  1. Generate entities from database
  2. Generate controllers from entity classes

When I generate entities from existing tables, you select which tables you want to create. Simply do this and do not select the 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 thing except select JPA Controller Classes from Entity Classes

mikeb
  • 10,578
  • 7
  • 62
  • 120
  • 1
    This doesn't answer the question of automatically adding `insertable = false, updatable = false` to the `current_timestamp` variable in the Entity – myselfmiqdad Feb 05 '16 at 15:46