-2

我的应用程序抛出此异常。我使用 Java DB 作为后端,我使用 JPA

内部异常:java.sql.SQLException:表/视图“POCKETMONEY”已存在于模式“APP”中。错误代码:30000 调用:CREATE TABLE APP.POCKETMONEY(ID INTEGER NOT NULL,DateofSpending DATE,DESCRIPTION VARCHAR(255),AMOUNT INTEGER,PRIMARY KEY (ID))查询:DataModifyQuery()

内部异常:java.sql.SQLException:表/视图 'SEQUENCE' 已存在于架构 'ADMIN' 中。错误代码:30000 调用:CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL, PRIMARY KEY (SEQ_NAME)) 查询:DataModifyQuery()

这是我的 JPA 代码

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mymoney;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author sugan
 */
@Entity
@Table(schema = "APP")
public class pocketMoney implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE)
    private int id;
    @Temporal(TemporalType.DATE)
    @Column(name = "DateofSpending")
    private Date dos;
    private String description;
    private int amount;

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getDos() {
        return dos;
    }

    public void setDos(Date dos) {
        this.dos = dos;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof pocketMoney)) {
            return false;
        }
        pocketMoney other = (pocketMoney) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mymoney.pocketMoney[id=" + id + "]";
    }
}

持久性.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
  <persistence-unit name="myMoneyPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>mymoney.pocketMoney</class>
    <properties>
      <property name="eclipselink.jdbc.password" value="adminadmin"/>
      <property name="eclipselink.jdbc.user" value="admin"/>
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
      <property name="eclipselink.jdbc.url" value="jdbc:derby:pocketmoney;create=true"/>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
    </properties>
  </persistence-unit>
</persistence>
4

1 回答 1

2

无论您使用什么 JPA 提供程序,我都怀疑它被配置为生成和导出与您的映射相对应的数据库对象......并且那些已经存在。

根据您的配置、JPA 提供程序、确切消息(EclipseLink 记录诸如警告 AFAIK 之类的消息),这可能只是正常的或“配置错误”。

如果您想了解更多详细信息,请告诉我们您使用的提供商并出示您的persistence.xml.

更新:正如怀疑的那样,您正在使用 EclipseLink 并且这些消息是“正常的”(如果您仔细查看消息 IIRC,它们将被记录为警告)

于 2010-09-01T08:59:41.397 回答