openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "seba.wagner@gmail.com" <seba.wag...@gmail.com>
Subject ALTER instead of ADD for table columns if the column is an auto_increment (or somehow unique) with openjpa.jdbc.SynchronizeMappings
Date Thu, 26 Jan 2012 14:13:24 GMT
If you're using the option openjpa.jdbc.SynchronizeMappings

openJPA is not able to rename a column that has is an auto-incrementor.

You get an error like that:
[ERROR] [Launcher:/openmeetings]
org.openmeetings.app.remote.red5.ScopeApplicationAdapter - [appStart]
org.springframework.transaction.CannotCreateTransactionException: Could not
open JPA EntityManager for transaction; nested exception is
<openjpa-2.1.0-r422266:1071316 *nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: Incorrect table
definition; there can be only one auto column and it must be defined as a
key {stmnt 1865566999 ALTER TABLE recording_conversion_job ADD job_id
BIGINT AUTO_INCREMENT} [code=1075, state=42000]*

The reason is: If renamed a column in my mapping files. The template is in
use in a MySQL database and the SchemaBuilder tries to update the table.
The SchemaUpdater fails as he cannot create a new column that is an auto
incrementor.
Actually it shouldn't do that, it should rename the existing column. There
can be only ONE primary key per table. The SchemaUpdater should use the
ALTER TABLE syntax if it detects that a new column needs to be created that
is a primary key.
I don't think it makes sense if you create a new column in an update script
for a primary key value, actually this update could invalidate your whole
database so maybe I am even lucky with the exception as the result that
openJPA would create might be more confusing then the error :)

Sebastian


-- 
Sebastian Wagner
http://www.openmeetings.de
http://incubator.apache.org/openmeetings/
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message