EclipseLink "create-or-ext-tables" doesn't work: "... unknown column ..."

I am using EclipseLink 2.4.1 with Glassfish and a persistent objects MySQL database.
I added a field to an object, and when I try to save that object, it says the new field is "unknown".
How are we supposed to use the new "create-or-extend-tables" function? I would think this would create a new column for this field.

Below is the relevant information, please let me know if you want more.

Thanks in advance!

Stack trace

...
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003 ad44345): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 't0.TESTFIELD' in 'field list'
Error Code: 1054
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
...

      

persistence.xml

<persistence-unit name="myApp" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/mysql</jta-data-source>
<mapping-file>META-INF/orm.xml</mapping-file>
<properties>
  <property name="eclipselink.ddl-generation.output-mode" value="database"/>
  <property name="eclipselink.jdbc.batch-writing" value="Buffered"/>
  <property name="eclipselink.logging.level" value="INFO"/>
  <property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
</properties>

      

additional information

drop-and-create-tables does work.
I am using merge (entity) to persist new entities (as they have many different fields, resulting in duplicate primary id errors). I feel like this could be a problem.
Looking at the MySQL log and the best log level from EclipseLink, EclipseLink first tries to
fetch an object from the database like this mysql_log:

121115 10:49:03 9 Query SELECT t0.LISTINGID, t0.DTYPE, ... , t0.TESTFIELD FROM the_entity...

      

This is the last mysql log entry meaning it crashes here, it never tries to drop a table, etc. Does that mean you can't use merge with drop-and-create or create-or-extend? I just did google and didn't find any information on this.

EclipseLink log entry:

FINER: client acquired: 64279491
FINER: TX binding to tx mgr, status=STATUS_ACTIVE
FINER: acquire unit of work: 161130796
FINEST: Merge clone with references nz.co.site.api.v1.ListedItemDetail@8d88ca1
FINEST: Execute query ReadObjectQuery(referenceClass=ListedItemDetail )
FINEST: Connection acquired from connection pool [read].
FINEST: reconnecting to external connection pool
FINE: SELECT t0.LISTINGID, t0.DTYPE, ... , t0.TESTFIELD, ... , FROM ITEM t0, LISTEDITEMDETAIL t1 WHERE ((t0.LISTINGID = ?) AND ((t1.LISTINGID = t0.LISTINGID) AND (t0.DTYPE = ?)))
bind => [2 parameters bound]
FINE: SELECT 1
FINEST: Connection released to connection pool [read].
WARNING: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.DatabaseException

      

I am using transaction management bean to merge new objects:

userTransaction.begin();
entityManager.merge(entity);
entityManager.flush();
userTransaction.commit();

      

0


source to share


1 answer


Glassfish intercepts the eclipselink.ddl-generation.output-mode property and forces it to write to a file as described in the answer here: eclipselink does not generate tables from JPA annotated classes So you will need to check that you have enabled java2db in Glassfish for the "drop- and-create-tables ".

"create-or-extend-tables" although requires a database connection to see what's in the database and therefore does not currently work with sql-script output mode. I'm not sure how to get Glassfish not to overwrite the exit mode property, but if that can't be done, you'll need to start your persistent glassfish sidebar in order to use this feature.



A workaround in glass shawl would be to try something like this:

Map properties = new HashMap();
properties.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.CREATE_OR_EXTEND);
//create-or-extend only works on the database
properties.put(PersistenceUnitProperties.DDL_GENERATION_MODE, PersistenceUnitProperties.DDL_DATABASE_GENERATION);
//this causes DDL generation to occur on refreshMetadata rather than wait until an em is obtained
properties.put(PersistenceUnitProperties.DEPLOY_ON_STARTUP, "true");
JpaHelper.getEntityManagerFactory(em).refreshMetadata(properties);

      

+3


source







All Articles