java.sql.SQLException:表/视图“SEQUENCE”;模式“ADMIN”中已存在;

发布于 2024-09-17 16:58:32 字数 3564 浏览 7 评论 0原文

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

内部异常: java.sql.SQLException:表/视图 模式中已存在“POCKETMONEY” '应用程序'。错误代码:30000 调用:CREATE 表 APP.POCKETMONEY(ID 整数不是 NULL,支出日期日期,描述 VARCHAR(255),金额整数,主要 KEY (ID)) 查询:DataModifyQuery()

内部异常: java.sql.SQLException:表/视图 架构中已存在“SEQUENCE” '行政'。错误代码:30000 呼叫: 创建表序列(SEQ_NAME VARCHAR(50) 非空,SEQ_COUNT 小数,主键(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 + "]";
    }
}

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

My application throws this Exception.
I am using Java DB as the back end and i am using JPA

Internal Exception:
java.sql.SQLException: Table/View
'POCKETMONEY' already exists in Schema
'APP'. Error Code: 30000 Call: CREATE
TABLE APP.POCKETMONEY (ID INTEGER NOT
NULL, DateofSpending DATE, DESCRIPTION
VARCHAR(255), AMOUNT INTEGER, PRIMARY
KEY (ID)) Query: DataModifyQuery()

Internal Exception:
java.sql.SQLException: Table/View
'SEQUENCE' already exists in Schema
'ADMIN'. Error Code: 30000 Call:
CREATE TABLE SEQUENCE (SEQ_NAME
VARCHAR(50) NOT NULL, SEQ_COUNT
DECIMAL, PRIMARY KEY (SEQ_NAME))
Query: DataModifyQuery()

Here is my JPA code

/*
 * 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 + "]";
    }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的她 2024-09-24 16:58:32

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

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

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

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

Whatever JPA provider you're using, I suspect that it is configured to generate and export the database objects corresponding to your mappings... and those already exist.

Depending on your configuration, on the JPA provider, on the exact message (EclipseLink logs such messages as warning AFAIK), this might be just normal or a "configuration mistake".

If you want more details, please tell us what provider you're using and show your persistence.xml.

Update: As suspected, you are using EclipseLink and these message are "normal" (they are logged as warning if you look closely at the message IIRC)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文