Search code examples
jpaeclipselink

jpa eclipselink modify field type


I'm making my first steps with JPA (eclipselink) developement, and i'm wondering if there's any good practice that may help reflecting changes brought to an entity into the data-base without re-creating the whole data-base.

In my case i have more than 30 entities, some of these are "correctly" defined and are already holding data rows on the data-base, but i've figured out that i made a mistake while defining some other entities by using the int type for the primary key instead of long, and the worst is that some of these entities are mapped by other entities, which means that they're used as foreign keys ... So i'm wondering if there's any "proper" way to deal with this without having to re-create the whole data-base. Re-creating the data-base will force me to re-fill the rows of the already filled tables and waist much time.

Thanks in Advance
George


Solution

  • ints and longs are mapped to a number column in database. Changing the type in the entities won't change anything. You might have to change the precision of the columns in database so that the number is sufficiently large to accept any long value, but doing that is trivial in SQL, using an alter statement.

    JPA is just a way to access the database. The database is not supposed to be created by the JPA engine. You may do that, but you're not forced to do that. You may do what you want with your database using SQL, and do whatever you want with your Java code. If they both map together when running the application, it will work.