javajdbceclipselinkjpa-2.1java-ee-8

Why the JPA drop-and-create option is not working


I am using, Apache Derby as the DB, EclipseLink JPA running on Glassfish 5.1, and Netbeans 12.0 as my development environment. I have bug down with this for several days and I don't seem to find my way out of it. So any help is greatly appreciated.

I have selected the drop-and-create option in the persistence.xml. I use generate scripts by the JPA to perform the drop-and-create operations.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd">
    <!-- Define Persistence Unit -->
    <persistence-unit name="listserviceDB" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:comp/DefaultDataSource</jta-data-source>
        <properties>
            <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
            <property name="javax.persistence.schema-generation.drop-source" value="script"/>
            <property name="javax.persistence.schema-generation.drop-script-source" value="META-INF/drop.sql"/>
            <property name="javax.persistence.schema-generation.create-source" value="script"/>
            <property name="javax.persistence.schema-generation.create-script-source" value="META-INF/create.sql"/>
            <property name="eclipselink.logging.level" value="FINE"/>
            <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/>
        </properties>
    </persistence-unit>
</persistence>

The drop script:

ALTER TABLE PERSISTENCE_LINEITEM DROP CONSTRAINT PRSSTNCLNEITEMPRTD
ALTER TABLE PERSISTENCE_LINEITEM DROP CONSTRAINT PRSSTNCLNITEMLNTMD
ALTER TABLE PERSISTENCE_ORDER DROP CONSTRAINT PRSSTNCORDERCNSMRD
DROP TABLE PERSISTENCE_LINEITEM
DROP TABLE PERSISTENCE_ORDER
DROP TABLE PERSISTENCE_USER
DROP TABLE PERSISTENCE_PART
DELETE FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN'

The create script:

CREATE TABLE PERSISTENCE_LINEITEM (ID BIGINT NOT NULL, QUANTITY INTEGER, LINEITEMID BIGINT, PART_ID BIGINT, PRIMARY KEY (ID))
CREATE TABLE PERSISTENCE_ORDER (ID BIGINT NOT NULL, LASTUPDATED TIMESTAMP, ORDERNUMBER VARCHAR(255), STATUS VARCHAR(255), TOTAL FLOAT, CONSUMERID BIGINT, PRIMARY KEY (ID))
CREATE TABLE PERSISTENCE_USER (ID BIGINT NOT NULL, CELLPHONE VARCHAR(255), COMPANY VARCHAR(255), DATEOFBIRTH DATE, EMAIL VARCHAR(255), FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), OFFICEPHONE VARCHAR(255), PASSWORD VARCHAR(255), USERID VARCHAR(255), USERROLE VARCHAR(255), PRIMARY KEY (ID))
CREATE TABLE PERSISTENCE_PART (ID BIGINT NOT NULL, DESCRIPTION VARCHAR(255), MANUFACTURE VARCHAR(255), NAME VARCHAR(255), NUMBER VARCHAR(255), PRICE FLOAT, PRIMARY KEY (ID))
ALTER TABLE PERSISTENCE_LINEITEM ADD CONSTRAINT PRSSTNCLNEITEMPRTD FOREIGN KEY (PART_ID) REFERENCES PERSISTENCE_PART (ID)
ALTER TABLE PERSISTENCE_LINEITEM ADD CONSTRAINT PRSSTNCLNITEMLNTMD FOREIGN KEY (LINEITEMID) REFERENCES PERSISTENCE_ORDER (ID)
ALTER TABLE PERSISTENCE_ORDER ADD CONSTRAINT PRSSTNCORDERCNSMRD FOREIGN KEY (CONSUMERID) REFERENCES PERSISTENCE_USER (ID)
CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))
INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0)

At the server startup, I use a @Singleton @Startup bean with a method marked with @PostConstruct annotation to load initial test data into the database from an XML file using JAXB. The application use to work fine until I added some mapping relationships to some of the entities. Now, for some reasons at the server start-up, the JPA cannot drop tables for those entities that have mapping relationships, consequently, the app is inserting data into the existing tables with data and that causes a "unique primary key constraint violation" exception to be thrown. As expected by the JEE spec, any application exceptions at the startup nulls out the CDIs in the beans (in my case the EntityManager injection becomes null) and that breaks the code. I have for entities "Part", "AppUser", "CustomerOrder" and "LineItem". The "Part" entity has no mapping relationship and therefore it gets created and loaded successfully but the rest of the entities have problem.

@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class DataLoaderSessionBean {
   @PostConstruct
   public void createData() {
      loadParts();
      loadUsers();
  }
}


 @Entity
    @Table(name = "PERSISTENCE_USER")
    public class AppUser implements Serializable {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @XmlTransient
        private Long id;
        @NotNull
        private String userId;
        @NotNull
        private String password;
        @NotNull
        private String userRole;
        @NotNull
        private String firstName;
        @NotNull
        private String lastName;
        @Temporal(TemporalType.DATE)
        @NotNull
        private Date dateOfBirth;
        @NotNul
        private String officePhone;
        private String cellPhone;
        private String email;
        private String company;
        @OneToMany (mappedBy = "consumer", cascade = CascadeType.ALL)
        private List<CustomerOrder> orders;

        }
@Entity
@Table(name = "PERSISTENCE_ORDER")
public class CustomerOrder implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    String status;
    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdated;
    @NotNull
    @OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
    private List<LineItem> lineItems;
    @NotNull
    @JoinColumn(name="CONSUMERID")
    @ManyToOne
    private AppUser consumer;
    @NotNull
    private Double total;
    @NotNull
    private String orderNumber;
}
@Entity
@Table(name = "PERSISTENCE_LINEITEM")
public class LineItem implements Serializable {
    private static final long serialVersionUID = 1991217202100959L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    private Integer quantity;
    @OneToOne
    private Part part;
    @NotNull
    @JoinColumn(name="LINEITEMID")
    @ManyToOne
    private CustomerOrder order;
}

@Entity
@Table(name = "PERSISTENCE_PART")
public class Part implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    private String name;
    @NotNull
    private String manufacture;
    @NotNull
    private String number;
    @NotNull
    private String description;
    @NotNull
    private double price;     
}

Following are the code snippet that read the data from the XML file and populate the User table:

private void loadUsers() {
        List<AppUser> users;
        try {
            JAXBContext context = JAXBContext
                    .newInstance(UserWrapper.class);
            Unmarshaller um = context.createUnmarshaller();
            //  InputStream input = DataLoaderSessionBean.class.getResourceAsStream(partPath);
            UserWrapper warpper = (UserWrapper) um.unmarshal(new File(userPath));
            users = warpper.getUsers();
            List<CustomerOrder> orders = getOrders(users.get(0));
            if (users != null) {
                logger.log(Level.INFO, "Total users loaded by JAXB: {0}", users.size());
                users
                        .stream()
                        .forEach(e->e.setOrders(orders));
                requestLogin.addUsers(users);
            } else {
                logger.log(Level.SEVERE, "Error: No users were loaded. The {0} file is emply, please check the file", userPath);
            }

        } catch (JAXBException e) {
            logger.log(Level.SEVERE, "Error: There was a problem reading the data from {0} file. Exception message {1}",
                    new Object[]{userPath, e.getMessage()});
           
        }
    }
private List<CustomerOrder> getOrders(AppUser u){
        List<CustomerOrder> orders = new ArrayList();
        CustomerOrder order = new CustomerOrder();
        //Creating LineItem
        Part part = requestPart.getPartByNumber("BC774091HA");
        LineItem line = new LineItem(part,2);
        double total = part.getPrice() * line.getQuantity();
        line.setOrder(order);
        List<LineItem> items = new ArrayList();
        items.add(line);
        order.setStatus("Pending Shipment");
        order.setLastUpdated(new Date());
        order.setLineItems(items);
        order.setTotal(total);
        order.setOrderNumber("OTTaviano234576907");
        order.setConsumer(u);
        orders.add(order);
        return orders;
    }


public void addUsers(List<AppUser> users) {
        users
                .stream()
                .forEach(this::addUser);
    }

    public void addUser(AppUser u) {
     //   public void addUser(AppUser u) throws ListServiceException {
        try {
            if (em != null) {
                if (em.isOpen()) {
                    if (u != null) {
                        logger.log(Level.FINEST, "User information to add: id {0} first {1} last {2} dob {3} phone {4}",
                                new Object[]{u.getUserId(), u.getFirstName(), u.getLastName(),
                                    u.getDateOfBirth(), u.getOfficePhone()});
                        em.persist(u);
                        logger.log(Level.FINEST, "The user with id {0} added successfuly",
                                u.getUserId());
                    } else {
                        logger.severe("NULL user can not be added");
                    }
                } else {
                    logger.severe("Entity manager is closed, user cannot be added");
                }
            } else {
                logger.severe("EntityManager is NULL, user cannot be added");
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Tony: Exception while adding user. Error msg {0}", e.getMessage());
            throw ThrowListServiceException.wrapException(e);
        }
    }

The snippet from the log file in chronological order:

 Connected: jdbc:derby://localhost:1527/sun-appserv-samples;;create=true
    User: APP
    Database: Apache Derby  Version: 10.14.2.0 - (1828579)
    Driver: Apache Derby Network Client JDBC Driver  Version: 10.14.2.0 - (1828579)]]
.....
ALTER TABLE PERSISTENCE_LINEITEM DROP CONSTRAINT PRSSTNCLNEITEMPRTD]]

ALTER TABLE PERSISTENCE_LINEITEM DROP CONSTRAINT PRSSTNCLNITEMLNTMD]]
  
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.PRSSTNCLNITEMLNTMD' on table '"APP"."PERSISTENCE_LINEITEM"'. 
Error Code: 30000
Call: ALTER TABLE PERSISTENCE_LINEITEM DROP CONSTRAINT PRSSTNCLNITEMLNTMD
Query: DataModifyQuery(sql="ALTER TABLE PERSISTENCE_LINEITEM DROP CONSTRAINT PRSSTNCLNITEMLNTMD")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
Caused by: java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.PRSSTNCLNITEMLNTMD' on table '"APP"."PERSISTENCE_LINEITEM"'. 
Caused by: ERROR 42X86: ALTER TABLE failed. There is no constraint 'APP.PRSSTNCLNITEMLNTMD' on table '"APP"."PERSISTENCE_LINEITEM"'. 
.......
  ALTER TABLE PERSISTENCE_ORDER DROP CONSTRAINT PRSSTNCORDERCNSMRD]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.PRSSTNCORDERCNSMRD' on table '"APP"."PERSISTENCE_ORDER"'. 
Error Code: 30000
Call: ALTER TABLE PERSISTENCE_ORDER DROP CONSTRAINT PRSSTNCORDERCNSMRD
Query: DataModifyQuery(sql="ALTER TABLE PERSISTENCE_ORDER DROP CONSTRAINT PRSSTNCORDERCNSMRD")
Caused by: java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.PRSSTNCORDERCNSMRD' on table '"APP"."PERSISTENCE_ORDER"'. 
Caused by: ERROR 42X86: ALTER TABLE failed. There is no constraint 'APP.PRSSTNCORDERCNSMRD' on table '"APP"."PERSISTENCE_ORDER"'. 
.....
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210226155716540' because CONSTRAINT 'PRSSTNCRDRPRLNTMSD' is dependent on that object.
Error Code: 30000
Call: DROP TABLE PERSISTENCE_LINEITEM
Query: DataModifyQuery(sql="DROP TABLE PERSISTENCE_LINEITEM")
Caused by: java.sql.SQLTransactionRollbackException: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210226155716540' because CONSTRAINT 'PRSSTNCRDRPRLNTMSD' is dependent on that object.
Caused by: ERROR X0Y25: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210226155716540' because CONSTRAINT 'PRSSTNCRDRPRLNTMSD' is dependent on that object.
.....
DROP TABLE PERSISTENCE_ORDER]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210223101327490' because CONSTRAINT 'PRSSTNCRDCSTMRRDRD' is dependent on that object.
Error Code: 30000
Call: DROP TABLE PERSISTENCE_ORDER
Query: DataModifyQuery(sql="DROP TABLE PERSISTENCE_ORDER")
Caused by: java.sql.SQLTransactionRollbackException: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210223101327490' because CONSTRAINT 'PRSSTNCRDCSTMRRDRD' is dependent on that object.
Caused by: ERROR X0Y25: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210223101327490' because CONSTRAINT 'PRSSTNCRDCSTMRRDRD' is dependent on that object.
......
DROP TABLE PERSISTENCE_USER]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210223101327520' because CONSTRAINT 'PRSSTNCSRPRSSTNSRD' is dependent on that object.
Error Code: 30000
Call: DROP TABLE PERSISTENCE_USER
Query: DataModifyQuery(sql="DROP TABLE PERSISTENCE_USER")
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
Caused by: java.sql.SQLTransactionRollbackException: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210223101327520' because CONSTRAINT 'PRSSTNCSRPRSSTNSRD' is dependent on that object.
Caused by: ERROR X0Y25: Operation 'DROP CONSTRAINT' cannot be performed on object 'SQL210223101327520' because CONSTRAINT 'PRSSTNCSRPRSSTNSRD' is dependent on that object.
....
DROP TABLE PERSISTENCE_PART]]
DELETE FROM SEQUENCE WHERE SEQ_NAME = 'SEQ_GEN']]
CREATE TABLE PERSISTENCE_LINEITEM (ID BIGINT NOT NULL, QUANTITY INTEGER, LINEITEMID BIGINT, PART_ID BIGINT, PRIMARY KEY (ID))]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Table/View 'PERSISTENCE_LINEITEM' already exists in Schema 'APP'.
Error Code: 30000
Call: CREATE TABLE PERSISTENCE_LINEITEM (ID BIGINT NOT NULL, QUANTITY INTEGER, LINEITEMID BIGINT, PART_ID BIGINT, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE PERSISTENCE_LINEITEM (ID BIGINT NOT NULL, QUANTITY INTEGER, LINEITEMID BIGINT, PART_ID BIGINT, PRIMARY KEY (ID))")
Caused by: java.sql.SQLTransactionRollbackException: Table/View 'PERSISTENCE_LINEITEM' already exists in Schema 'APP'.
Caused by: ERROR X0Y32: Table/View 'PERSISTENCE_LINEITEM' already exists in Schema 'APP'.
.....
CREATE TABLE PERSISTENCE_ORDER (ID BIGINT NOT NULL, LASTUPDATED TIMESTAMP, ORDERNUMBER VARCHAR(255), STATUS VARCHAR(255), TOTAL FLOAT, CONSUMERID BIGINT, PRIMARY KEY (ID))]]  
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Table/View 'PERSISTENCE_ORDER' already exists in Schema 'APP'.
Error Code: 30000
Call: CREATE TABLE PERSISTENCE_ORDER (ID BIGINT NOT NULL, LASTUPDATED TIMESTAMP, ORDERNUMBER VARCHAR(255), STATUS VARCHAR(255), TOTAL FLOAT, CONSUMERID BIGINT, PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE PERSISTENCE_ORDER (ID BIGINT NOT NULL, LASTUPDATED TIMESTAMP, ORDERNUMBER VARCHAR(255), STATUS VARCHAR(255), TOTAL FLOAT, CONSUMERID BIGINT, PRIMARY KEY (ID))")
Caused by: java.sql.SQLTransactionRollbackException: Table/View 'PERSISTENCE_ORDER' already exists in Schema 'APP'.
Caused by: ERROR X0Y32: Table/View 'PERSISTENCE_ORDER' already exists in Schema 'APP'.
.....
CREATE TABLE PERSISTENCE_USER (ID BIGINT NOT NULL, CELLPHONE VARCHAR(255), COMPANY VARCHAR(255), DATEOFBIRTH DATE, EMAIL VARCHAR(255), FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), OFFICEPHONE VARCHAR(255), PASSWORD VARCHAR(255), USERID VARCHAR(255), USERROLE VARCHAR(255), PRIMARY KEY (ID))]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Table/View 'PERSISTENCE_USER' already exists in Schema 'APP'.
Error Code: 30000
Call: CREATE TABLE PERSISTENCE_USER (ID BIGINT NOT NULL, CELLPHONE VARCHAR(255), COMPANY VARCHAR(255), DATEOFBIRTH DATE, EMAIL VARCHAR(255), FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), OFFICEPHONE VARCHAR(255), PASSWORD VARCHAR(255), USERID VARCHAR(255), USERROLE VARCHAR(255), PRIMARY KEY (ID))
Query: DataModifyQuery(sql="CREATE TABLE PERSISTENCE_USER (ID BIGINT NOT NULL, CELLPHONE VARCHAR(255), COMPANY VARCHAR(255), DATEOFBIRTH DATE, EMAIL VARCHAR(255), FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), OFFICEPHONE VARCHAR(255), PASSWORD VARCHAR(255), USERID VARCHAR(255), USERROLE VARCHAR(255), PRIMARY KEY (ID))")
Caused by: java.sql.SQLTransactionRollbackException: Table/View 'PERSISTENCE_USER' already exists in Schema 'APP'.
Caused by: ERROR X0Y32: Table/View 'PERSISTENCE_USER' already exists in Schema 'APP'.
......
CREATE TABLE PERSISTENCE_PART (ID BIGINT NOT NULL, DESCRIPTION VARCHAR(255), MANUFACTURE VARCHAR(255), NAME VARCHAR(255), NUMBER VARCHAR(255), PRICE FLOAT, PRIMARY KEY (ID))]]
ALTER TABLE PERSISTENCE_LINEITEM ADD CONSTRAINT PRSSTNCLNEITEMPRTD FOREIGN KEY (PART_ID) REFERENCES PERSISTENCE_PART (ID)]]
ALTER TABLE PERSISTENCE_LINEITEM ADD CONSTRAINT PRSSTNCLNITEMLNTMD FOREIGN KEY (LINEITEMID) REFERENCES PERSISTENCE_ORDER (ID)]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: 'LINEITEMID' is not a column in table or VTI 'PERSISTENCE_LINEITEM'.
Error Code: 30000
Call: ALTER TABLE PERSISTENCE_LINEITEM ADD CONSTRAINT PRSSTNCLNITEMLNTMD FOREIGN KEY (LINEITEMID) REFERENCES PERSISTENCE_ORDER (ID)
Query: DataModifyQuery(sql="ALTER TABLE PERSISTENCE_LINEITEM ADD CONSTRAINT PRSSTNCLNITEMLNTMD FOREIGN KEY (LINEITEMID) REFERENCES PERSISTENCE_ORDER (ID)")
Caused by: java.sql.SQLSyntaxErrorException: 'LINEITEMID' is not a column in table or VTI 'PERSISTENCE_LINEITEM'.
Caused by: ERROR 42X14: 'LINEITEMID' is not a column in table or VTI 'PERSISTENCE_LINEITEM'.
......
ALTER TABLE PERSISTENCE_ORDER ADD CONSTRAINT PRSSTNCORDERCNSMRD FOREIGN KEY (CONSUMERID) REFERENCES PERSISTENCE_USER (ID)]]  
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: 'CONSUMERID' is not a column in table or VTI 'PERSISTENCE_ORDER'.
Error Code: 30000
Call: ALTER TABLE PERSISTENCE_ORDER ADD CONSTRAINT PRSSTNCORDERCNSMRD FOREIGN KEY (CONSUMERID) REFERENCES PERSISTENCE_USER (ID)
Query: DataModifyQuery(sql="ALTER TABLE PERSISTENCE_ORDER ADD CONSTRAINT PRSSTNCORDERCNSMRD FOREIGN KEY (CONSUMERID) REFERENCES PERSISTENCE_USER (ID)")
Caused by: java.sql.SQLSyntaxErrorException: 'CONSUMERID' is not a column in table or VTI 'PERSISTENCE_ORDER'.
Caused by: ERROR 42X14: 'CONSUMERID' is not a column in table or VTI 'PERSISTENCE_ORDER'.
......
CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))]]
Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: Table/View 'SEQUENCE' already exists in Schema 'APP'.
Error Code: 30000
Call: CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))
Query: DataModifyQuery(sql="CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(15), PRIMARY KEY (SEQ_NAME))")
Caused by: java.sql.SQLTransactionRollbackException: Table/View 'SEQUENCE' already exists in Schema 'APP'.
Caused by: ERROR X0Y32: Table/View 'SEQUENCE' already exists in Schema 'APP'.
......
  INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0)
  Total records loaded into Part Table successfuly by JAXB: 19
.....
INSERT INTO PERSISTENCE_USER (ID, CELLPHONE, COMPANY, DATEOFBIRTH, EMAIL, FIRSTNAME, LASTNAME, OFFICEPHONE, PASSWORD, USERID, USERROLE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [20, (917)-971-6854, Leman Brothers, 2020-12-29, null, Joseph, Ottaviano, (718)-815-8111, admin, admin, superadmin]]]

Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.0.v20170811-d680af5): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL210223101327520' defined on 'PERSISTENCE_USER'.
Error Code: 20000
Call: INSERT INTO PERSISTENCE_USER (ID, CELLPHONE, COMPANY, DATEOFBIRTH, EMAIL, FIRSTNAME, LASTNAME, OFFICEPHONE, PASSWORD, USERID, USERROLE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    bind => [20, (917)-971-6854, Leman Brothers, 2020-12-29, null, Joseph, Ottaviano, (718)-815-8111, admin, admin, superadmin]
Query: InsertObjectQuery(org.me.mavenlistservicedb.entity.AppUser@65038c6d)
Caused by: org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL210223101327520' defined on 'PERSISTENCE_USER'.
Caused by: ERROR 23505: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL210223101327520' defined on 'PERSISTENCE_USER'.

Any idea why these tables are not dropped?

Thanks in advance

Solution

  • The problem had to do with the DB configuration in the Netbeans IDE. From Services->Database->Java DB I changed the properties to point to the Derby installation in my system and not the one that's embedded with the Glassfish. I killed the process that was listening on port 1527 (specific for derby). I restarted the IDE, the DB server, and the app runs fine (well almost fine).