Heroku spring-jpa UniqueConstraint

时间:2018-03-02 23:35:58

标签: heroku spring-data-jpa

我遇到了一个问题:在我的课程项目中,我使用spring-jpa并使用两个唯一字段创建UserEntity。在我的本地机器上,所有工作都很好(在db中创建了唯一的约束),但是在heroku上没有创建唯一的约束。 我使用java9 + spring-jpa。

import javax.persistence.*;

@Entity(name = "UserEntity")
@Table(name = "user_entity", uniqueConstraints = {
        @UniqueConstraint(columnNames = {"nickname"}, name = "nickname_constraint"),
        @UniqueConstraint(columnNames = {"email"}, name = "email_constraint")
})
public class UserEntity {
    private Integer id;
    private String nickname;
    private String email;
    private String passwordHash;
    private String avatarPath;
    private GameResults gameResults;

    public UserEntity() {
    }

    public UserEntity(String nickname, String email, String password) {
        this.nickname = nickname;
        this.email = email;
        this.passwordHash = password;
    }

    public UserEntity(String nickname, String password) {
        this.nickname = nickname;
        this.passwordHash = password;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    @Column(name = "nickname")
    public String getNickname() {
        return this.nickname;
    }

    @Column(name = "avatar_path")
    public String getAvatarPath() {
        return avatarPath;
    }

    @Column(name = "email")
    public String getEmail() {
        return email;
    }

    @Column(name = "password_hash")
    public String getPasswordHash() {
        return passwordHash;
    }

    @OneToOne(fetch = FetchType.LAZY)
    public GameResults getGameResults() {
        return gameResults;
    }
    // setters ommited
}

1 个答案:

答案 0 :(得分:0)

谢谢jusermar10! 真的,问题是我第一次用不正确的jpa实体部署了应用程序。重新部署固定版本的应用程序后,postgres中没有必要的约束。所以丢弃db并重新启动所有dynos帮助了我。