How do I add a column to a JPA entity, and still keep my data? -


during development of jpa application, added field "type" entity. caused application fail start with

caused by: exception [eclipselink-4002] (eclipse persistence services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.databaseexception internal exception: java.sql.sqlsyntaxerrorexception: column 't1.type' either not in table in list or appears within join specification , outside scope of join specification or appears in having clause , not in group list. if create or alter table  statement 't1.type' not column in target table. error code: -1 

during selection.

is there way alter table on startup, match current entity definitions? notice when app starts calls create table each table, fails , carries on.

in past when i've added fields entities delete database , start again. ok me if want add field entry when developing next release of software, how upgrade clients without losing there data?

thanks in advance - phil.

generally speaking, database generators of jpa providers not reliable creating , updating production databases. suppose in version 1 had field named name user entity , in version 2 replace firstname , lastname. in such cases db generator unable migrate schema correctly.

in other words, jpa provider's automatic db generation useful development , not production.

instead, can consider using database migration tool liquibase.

having said that, while eclipselink not support way updating, rather re-creating, tables using eclipselink.ddl-generation property, other jpa providers (e.g. hibernate) support updating of database tables. however, can not relied on production use fail in cases given example.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -