• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I delete entity class and create new one after changes

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been making a Java application in NetBeans, I recently made changes to the structure of the database by altering some of the tables. I had already created entity classes from the database however now I have made changes to the tables these are now out of date.

Am I safe to just delete the existing classes and then create new ones?

Any advice would be appreciated.
 
Saloon Keeper
Posts: 27819
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't even have to delete them. In fact, some JPA utilities can even synchronize your live database schema and its corresponding JPA Entity class files.

There's nothing especially magic about JPA Entity classes themselves. They're just POJOs. The magic all comes from the JPA runtime, which scans the class annotations and rewrites the internals of the classes to make them work within the JPA framework.
 
Tim Holloway
Saloon Keeper
Posts: 27819
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yeah. There is also nothing NetBeans-related in this. It's all part of Enterprise Java.
 
DanBoy Smith
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:You don't even have to delete them. In fact, some JPA utilities can even synchronize your live database schema and its corresponding JPA Entity class files.

There's nothing especially magic about JPA Entity classes themselves. They're just POJOs. The magic all comes from the JPA runtime, which scans the class annotations and rewrites the internals of the classes to make them work within the JPA framework.



Hi Tim,

thanks for your replies. I was wondering though, I did run the 'create entity classes from database' again for one of the tables however it did not fully reflect the changes I made to the table.

For example,  @NamedQueries were still there for the columns I removed and there were no new @NamedQueries for the new columns I added. And all the getter and setter methods were still there for the old columns.
Why is this?
 
Tim Holloway
Saloon Keeper
Posts: 27819
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you used an automated tool, it may have used some options that didn't match up well with what you wanted. In that case, I'd delete the source and class files and re-run the tool and see if the new results were more pleasing.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic