Q:

String as Id for Spring entity

I am trying create entity with String id:
@Entity
@NoArgsConstructor
@Getter @Setter
public class Account {

    @Id
    private String username;

    private String password;

    public Account(String username, String password) {
        this(username, username + "pass");
    }

    public Account(String username, String password) {
        this.username = username;
        this.password = password;
    }
}

But I can't save this entity: accounts.save(new Account(name, pass));
Error: org.springframework.orm.jpa.JpaSystemException: ids for this class must be manually assigned before calling save():
What's wrong?

A:

If you want to assign ids automatically on save then you must annotate ID column with @GeneratedValue(strategy=GenerationType.IDENTITY)

