0

I'm creating a Java Spring Boot Web app and earlier today I dropped all contents of one of my tables called 'users'. In my app, the 'admin' (me) is able to register other users on the app so that they can login and use the app.

Everything was working fine prior to me doing a drop table users command in MySQL Workbench. And now, when I go to register a user, rather than working properly, I get an error saying:

'Data too long for column 'password' at row 1'.

This was never an issue before and I'm not sure why it is now, but I have changed none of the code, and am not sure what code I could potentially attach in this post in order to further clarify the question.

Any help would be appreciated on either to

  1. Restore the table to where it was (which I don't think a rollback is possible here)
  2. Figure out what might've changed in the code.

Below I have the creation of the entity, but again, I changed none of this and everything was working fine. I do have encryption going on as well, but again, the only thing I did was drop the table and then have it recreated when running it as a 'Java Application', like I've always been doing.

package bcoreHW.model;

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.Transient;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import bcoreHW.validation.PasswordMatch;


@Entity
@Table(name="Users")
@PasswordMatch(message="{register.repeatPassword.mismatch}")
public class SiteUser {

    @Id
    @Column(name="userId")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long userId;

    @Column(name="email", unique=true)
    @Email(message="{register.email.invalid}")
    @NotBlank(message="{register.email.invalid}")
    private String email;

    @Transient // meaning it will not be saved in DB
    @Size(min=5, max=15, message="{register.password.size}")
    private String plainPassword; //unencrytped

    @Transient
    private String repeatPassword;

    @Column(name="password", length=50)
    private String password;

    @Column(name="role", length=20)
    private String role;


    public String getPlainPassword() {
        return plainPassword;
    }


    public void setPlainPassword(String plainPassword) {
        this.password = new BCryptPasswordEncoder().encode(plainPassword);
        this.plainPassword = plainPassword;
    }

    public String getRole() {
        return role;
    }


    public void setRole(String role) {
        this.role = role;
    }


    public Long getUserId() {
        return userId;
    }


    public void setUserId(Long userId) {
        this.userId = userId;
    }


    public String getEmail() {
        return email;
    }


    public void setEmail(String email) {
        this.email = email;
    }


    public String getPassword() {
        return password;
    }


    public void setPassword(String password) {
        this.password = password;
    }


    public String getRepeatPassword() {
        return repeatPassword;
    }


    public void setRepeatPassword(String repeatPassword) {
        this.repeatPassword = repeatPassword;
    }
}

Justin Pearce
  • 4,994
  • 2
  • 24
  • 37
CDA the Programmer
  • 87
  • 1
  • 6
  • 20
  • To clarify, where was the `users` table you dropped? Was it locally / in development or was it in some other environment? – Justin Pearce Jun 17 '20 at 18:27
  • Users table is local. Everything is local. – CDA the Programmer Jun 17 '20 at 18:34
  • You called out encryption. Was this something added recently? Is it possible the `password` column needs to be defined larger? – Justin Pearce Jun 17 '20 at 19:18
  • It's possible but the encryption was previously working and, as you can see in the model above, I have max char values set on the necessary values. Like I said, these values/variables haven't changed. Maybe I have to try to disable the encryption to figure out if that's where the problem lies. – CDA the Programmer Jun 17 '20 at 19:22
  • You may also look at your configuration. Take a look at https://stackoverflow.com/questions/42135114/how-does-spring-jpa-hibernate-ddl-auto-property-exactly-work-in-spring – Justin Pearce Jun 17 '20 at 19:26
  • No new answers found. I'm at a loss now. – CDA the Programmer Jun 17 '20 at 20:20
  • I did a complete reset of my project to yesterday's version that was working completely. So, now there is no question that the only difference is that I simply did a table drop of 'Users'. I'm really not sure what could be the problem. – CDA the Programmer Jun 17 '20 at 21:49
  • I've done some debugging and the length of the encrypted password is maxing out at 60, but even if I put length=60 or @Size(max=100), or something similar, I get the same error – CDA the Programmer Jun 17 '20 at 22:09

0 Answers0