I am using JPA2
, EclipseLink
. I am trying to add a new column to the existing database and table. I added a new field in POJO class MyTable. Inspite of having create-or-extend-tables
properties, the new column is not getting added up.
Here is my persistence.xml
file.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="idpersistance">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.id.service.db.pojo.AppTable</class>
<class>com.id.service.db.pojo.MyTable</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"></property>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:2705/mydb"></property>
<property name="javax.persistence.jdbc.user" value="user"></property>
<property name="javax.persistence.jdbc.password" value="password"></property>
<property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.id-validation" value="NULL"></property>
<property name="eclipselink.logging.level" value="FINE"/>
<property name="javax.persistence.lock.timeout" value="1000"/>
<property name="eclipselink.target-database" value="MySQL"/>
</properties>
</persistence-unit>
</persistence>
I am not sure why the new column is not getting added. I am getting back following error:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: null, message from server: "Unknown column 'newcol' in 'field list'"
Error Code: 1054
The jar
file that I am using:
eclipselink.jar (2.5.2)
javax.persistence_2.1.0.v201304241213.jar
Please let me know if any thing missing in my persistence.xml
file.
Any help is Appreciated.
Update:
I had debugged into EclipseLink
code and found that it is not attempting to generate new columns, it throws an error at extendDefaultTables()
method in EntityManagerFactoryProvider
class and says table already exists and returns from that method.
There is a field called useExternalConnectionPooling
in incrementCallCount()
method of DatasourceAccessor
class, if I set this field to true manually. Then new columns are getting generated successfully. Because of the field is false, EclipseLink
is not triggering extend. I am not sure, if this is correct field to go with.