Monday, April 29, 2013

How to update database schema when JPA entity changes

  4. Update database when entity changed.
  5. Setting up load balance database connection.
  6. Setting Cache Coordination in Eclipselink

It is always changes on database tables' fields during development.
For normal approach, we probably update the database schema first and follow by the entity (both are manual process).

Now, there could be alternative by JPA provider (either Hibernate or EclipseLink).
When the JPA provider detected change(s) on entities, it will update database schema to compliance with the working copy of entities.

What we need to do is only configure to JPA provider in persistence.xml


Steps:
1. add the following line to persistence.xml if Hibernate being used.
<property name="hibernate.hbm2ddl.auto" value="update" />
 
    add the following line to persistence.xml if EclipseLink being used
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />

Output:
If Hibernate being used, when updating database schema, the console would looks similar like below.
updating schema with Hibernate

If EclipseLink being used, when updating database schema, the console would looks similar like below.
updating schema with EclipseLink



PREV Testing the JPA project


Done!!

1 comment:

LinkWithin

Related Posts Plugin for WordPress, Blogger...