简体   繁体   English

在我的数据库 Java Derby 中插入新数据时生成的 ID 错误

[英]Error with the ID generated when i insert new data in my database Java Derby

i am building an app with a function to insert new Users in the database with Java Derby.我正在构建一个应用程序,该应用程序具有使用 Java Derby 在数据库中插入新用户的功能。

Everything is going well, but when i close the app, i run it again and i try to insert a new User (called USUARIO in the DB) the new ID generated of the User is one hundred times more than the last one on the last run.一切都很顺利,但是当我关闭应用程序时,我再次运行它并尝试插入一个新用户(在数据库中称为 USUARIO),该用户生成的新 ID 是最后一个用户 ID 的一百倍跑。

This is the output console that it shows me:这是它向我展示的输出控制台:

1)Nombre NombreEmail email
2)Nombre NombreEmail emailt
3)Nombre NombreEmail emailte
4)Nombre NombreEmail emailteet
5)Nombre Email tetete
6)Nombre Email tetetetetetet
7)Nombre Email tetetetetetettetetet
8)Nombre Email tetetetetetetteteteteeeeee
9)Nombre Email 

// At this moment i closed the app, and run it again...
// The new Register ID is starting up 100!

101)Nombre LuisEmail kik196@hotmail.com
102)Nombre Email ghjghjghjghjghjg
103)Nombre Email ghjghjghjjytyutu
104)Nombre Email ghjghjghjjytyututyrtytryr

This is the code that i am creating new data:这是我正在创建新数据的代码:

public void createUser(String nombre, String email, String apellido, String cedula, String telefono, String contraseña) {

        Usuario usuarioNuevo = new Usuario(email, nombre, apellido, contraseña, cedula, telefono);
        em.getTransaction().begin();
        em.persist(usuarioNuevo);
        em.getTransaction().commit();
    }

This is my entity Usuario class:这是我的实体 Usuario 类:

public class Usuario implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "EMAIL")
    private String email;
    @Basic(optional = false)
    @Column(name = "NOMBRES")
    private String nombres;
    @Basic(optional = false)
    @Column(name = "APELLIDOS")
    private String apellidos;
    @Basic(optional = false)
    @Column(name = "CONTRASE\u00d1A")
    private String contraseña;
    @Column(name = "CEDULA")
    private String cedula;
    @Column(name = "TELEFONO")
    private String telefono;

    public Usuario(){

    }

    public Usuario(String email, String nombres, String apellidos, String contraseña, String cedula, String telefono) {
        this.email = email;
        this.nombres = nombres;
        this.apellidos = apellidos;
        this.contraseña = contraseña;
        this.cedula = cedula;
        this.telefono = telefono;
    }

    public Usuario(Integer id) {
        this.id = id;
    }

     ....

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        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 Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "ComandosSQL.sql.Usuario[ id=" + id + " ]";
    }

}

I dont know what could be happening here.我不知道这里会发生什么。

Any help?有什么帮助吗? thank you!谢谢你!

This could happen when you hadn't shut down Derby.这可能发生在您没有关闭 Derby 时。 See derby.language.sequence.preallocator .请参阅derby.language.sequence.preallocator

You can shut down by adding ;shutdown=true to your JDBC URL.您可以通过将;shutdown=true添加到您的 JDBC URL 来;shutdown=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将新的一行数据添加到我的Derby数据库中? - How do I add a new row of data into my Derby database? 运行生成的 jar 文件时,如何使 Apache Derby 数据库正常工作? - How can I make my Apache Derby database work when I run my generated jar file? 无法使用 Java/JSP 将数据插入 Apache Derby 数据库 - Unable to insert data into Apache Derby database using Java/JSP 运行代码时,我在 Java Derby 数据库中收到此外键错误 - I am getting this foreign key error in Java Derby database when I run the code apache Derby - 在创建新数据库时获取java.io.FileNotFoundException:derby.log(拒绝访问) - apache Derby - getting java.io.FileNotFoundException: derby.log (Access is denied) when creating new database 使用JDBC在Apache Derby数据库中执行批量插入时,出现语法错误:DERBY-PROPERTIES。 我究竟做错了什么? - When preforming bulk insert in Apache Derby database using JDBC, I get a Syntax error: DERBY-PROPERTIES. What am I doing wrong? 当我尝试从数据库Derby DB中选择数据时出现奇怪的错误 - Strange error when I try to select data from database Derby DB 将 Java.sql.Date 插入 Derby 数据库 - Insert Java.sql.Date into Derby Database 我在使用Java将数据插入mysql数据库时遇到问题 - I have problems to insert data into my mysql Database using Java 将语句插入 Derby 数据库 - Insert Statement into Derby Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM