为什么JPA拖放创建选项不起作用 [英] Why the JPA drop-and-create option is not working

查看:82
本文介绍了为什么JPA拖放创建选项不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Derby作为数据库,在Glassfish 5.1上运行的EclipseLink JPA,以及Netbeans 12.0作为我的开发环境.我已经花了几天的时间来解决这个问题,但似乎并没有找到解决的办法.因此,非常感谢您的帮助.

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.

我在persistence.xml中选择了放置和创建选项.我使用JPA的生成脚本来执行拖放操作.

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>

放置脚本:

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'

创建脚本:

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)

在服务器启动时,我使用@Singleton @Startup bean和标有@PostConstruct批注的方法,以使用JAXB将初始测试数据从XML文件加载到数据库中.在我向某些实体添加一些映射关系之前,该应用程序可以正常工作.现在,由于服务器启动时的某些原因,JPA无法删除具有映射关系的那些实体的表,因此,该应用将数据插入到具有数据的现有表中,并导致唯一主键约束冲突".抛出异常.正如JEE规范所预期的那样,启动时任何应用程序异常都会使Bean中的CDI无效(在我的情况下,EntityManager注入变为null),这会破坏代码.我有实体"Part","AppUser","CustomerOrder"和"LineItem".部分"是指实体没有映射关系,因此可以成功创建和加载该实体,但其余实体存在问题.

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;     
}

以下是从XML文件读取数据并填充User表的代码段:

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?

推荐答案

问题与Netbeans IDE中的数据库配置有关.从Services-> Database-> Java DB,我更改了属性以指向系统中的Derby安装,而不是指向Glassfish内嵌的安装.我杀死了在端口1527上侦听的进程(特定于derby).我重新启动了IDE,数据库服务器,该应用程序运行正常(很好).

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).

这篇关于为什么JPA拖放创建选项不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆