0

I'm using eclipseLink 2.5.1 and through persistence.xml i'm able to create tables in DB by using entity classes(Java classes annotated with @Entity), those classes are listed in persistence.xml.

Problem: All classes which are defined in persistence.xml are creating tables in Db but i need only some classes of them i.e., eclipseLink should ignore some classes not to generate tables. Is there any solution to stop auto generation of tables in DB?

NOTE: Not all classes only some classes i need to omit from creation of tables in DB.

CaliCo
  • 39
  • 10
  • 1
    Really, generating tables from entities is useful for quick prototypes, but you shouldn't rely on it for serious work, and especially not for evolving an existing schema. I'd suggest using FlywayDB or Liquibase to generate and evolve your tables. – JB Nizet Jan 20 '15 at 07:29
  • Hi JB, creation of tables in DB will happen only while installing my application in client server not daily basis. so, DB doesn't matter, i need to skip some classes because those are not under single persistence unit but i require those in single persistence unit for mapping between schema's. Pls help in how to skip those classes? – CaliCo Jan 20 '15 at 09:10

1 Answers1

0

JPA 2.1 can be used to generate and execute scripts to create tables for you, with properties outlined here: https://blogs.oracle.com/arungupta/entry/jpa_2_1_schema_generation

You can then generate a DDL script and edit out the create table statements you do not want, and have your persistence unit call this script when needed.

Another alternative is to create a different persistence unit that only contains the entities with the needed tables. This persistence unit can then be used only to create the scripts - or called in your application to create the tables at startup.

If you are not using JPA 2.1, you can access EclipseLink's native properties to write out scripts and execute them yourself: http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_ddl_generation.htm#BABHEJJI

Chris
  • 20,138
  • 2
  • 29
  • 43
  • Thank you very much @Chris, second alternative will not work for me because i'm already using two different pu's but for case of mapping between two schema's i need to write those classes in same pu(duplication in both pu's). I hope first case is what i needed. – CaliCo Jan 21 '15 at 04:14