Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate ConstraintViolationException:具有临时confirmPassword字段的用户实体_Hibernate_Spring_Spring 3_Hibernate Validator - Fatal编程技术网

Hibernate ConstraintViolationException:具有临时confirmPassword字段的用户实体

Hibernate ConstraintViolationException:具有临时confirmPassword字段的用户实体,hibernate,spring,spring-3,hibernate-validator,Hibernate,Spring,Spring 3,Hibernate Validator,我不能提交我的春季表格。我遇到了这个异常,不知道为什么: javax.validation.ConstraintViolationException: validation failed for classes [com.example.my.entities.User] during persist time for groups [javax.validation.groups.Default, ] 这是我的用户实体: @Entity @Table( name = "tbl_user" )

我不能提交我的春季表格。我遇到了这个异常,不知道为什么:

javax.validation.ConstraintViolationException: validation failed for classes [com.example.my.entities.User] during persist time for groups [javax.validation.groups.Default, ]
这是我的用户实体:

@Entity
@Table( name = "tbl_user" )
public class User implements Serializable
{
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue
  @Column( name = "id", nullable = false, columnDefinition = "serial" )
  private int id;

  @NotEmpty
  @Length( max = 255 )
  @Column( name = "username", unique = true, nullable = false, length = 255 )
  private String username;

  @NotEmpty
  @Column( name = "password", nullable = false, length = 32 )
  private String password;

  @NotEmpty
  @Transient
  private String confirmPassword;

  @NotEmpty
  @Email
  @Length( max = 255 )
  @Column( name = "email", unique = true, nullable = false, length = 255 )
  private String email;

  @Length( max = 255 )
  @Column( name = "role", length = 255 )
  private String role;

  @OneToMany( fetch = FetchType.LAZY, mappedBy = "id.user", cascade = { CascadeType.REMOVE }, orphanRemoval = true )
  private List<LicenseUserAlert> alerts;

  public int getId()
  {
    return id;
  }

  public void setId( int id )
  {
    this.id = id;
  }

  public String getUsername()
  {
    return username;
  }

  public void setUsername( String username )
  {
    this.username = username;
  }

  public String getPassword()
  {
    return password;
  }

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

  public String getConfirmPassword()
  {
    return confirmPassword;
  }

  public void setConfirmPassword( String confirmPassword )
  {
    this.confirmPassword = confirmPassword;
  }

  public String getEmail()
  {
    return email;
  }

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

  public String getRole()
  {
    return role;
  }

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

  public List<LicenseUserAlert> getAlerts()
  {
    return alerts;
  }

  public void setAlerts( List<LicenseUserAlert> alerts )
  {
    this.alerts = alerts;
  }
}
@实体
@表(name=“tbl\U用户”)
公共类用户实现可序列化
{
私有静态最终长serialVersionUID=1L;
@身份证
@生成值
@列(name=“id”,nullable=false,columnDefinition=“serial”)
私有int-id;
@空空如也
@长度(最大值=255)
@列(name=“username”,unique=true,nullable=false,length=255)
私有字符串用户名;
@空空如也
@列(name=“password”,null=false,长度=32)
私有字符串密码;
@空空如也
@短暂的
私有字符串确认密码;
@空空如也
@电子邮件
@长度(最大值=255)
@列(name=“email”,unique=true,nullable=false,length=255)
私人字符串电子邮件;
@长度(最大值=255)
@列(name=“role”,长度=255)
私有字符串角色;
@OneToMany(fetch=FetchType.LAZY,mappedBy=“id.user”,cascade={CascadeType.REMOVE},orphanremove=true)
私人名单警报;
公共int getId()
{
返回id;
}
公共无效集合id(内部id)
{
this.id=id;
}
公共字符串getUsername()
{
返回用户名;
}
public void setUsername(字符串用户名)
{
this.username=用户名;
}
公共字符串getPassword()
{
返回密码;
}
public void setPassword(字符串密码)
{
this.password=密码;
}
公共字符串getConfirmPassword()
{
返回确认密码;
}
public void setConfirmPassword(字符串confirmPassword)
{
this.confirmPassword=confirmPassword;
}
公共字符串getEmail()
{
回复邮件;
}
公用电子邮件(字符串电子邮件)
{
this.email=电子邮件;
}
公共字符串getRole()
{
返回角色;
}
公共void setRole(字符串角色)
{
this.role=角色;
}
公共列表getAlerts()
{
返回警报;
}
公共无效设置警报(列出警报)
{
this.alerts=警报;
}
}
我正确填写了表格,所以不应该有任何违反约束的情况。。。
confirmPassword可能有问题吗?

您应该考虑将
confirmPassword
@NotNull
注释放在非默认验证组中

即使我相信由OR映射器验证
@瞬态
字段是一个bug。但也许JPA或Hibernate会有另一种看法如果您可以验证问题是否属于瞬态领域,并且您同意我的意见,那么您可以在hibernates bug tracker上发布一条提示

已添加 出于某种奇怪的原因,hibernate确实在验证字段,即使它们被标记为@Transient。 看这个论坛

另一个想法是不使用实体来包含仅用于GUI的字段。因此,您可能需要将表单数据容器(命令对象)与实体对象分开


@参见

例外情况说明具体数据不符合要求。(Hibernate也会检查constains(您可以配置它))要存储的实体的concreate数据是什么?我有点担心默认组
[javax.validation.groups.default,]
后面的分隔符。这可能只是一个没有很好完成的格式化问题,或者hibernate真的试图验证第二个没有名字的组。顺便说一句:对于密码确认,请看一看,因此我想如果不添加一些java代码,就不可能放入另一个组中?如果没有必要,我不想添加一个空接口。但是
@NotEmpty(groups=NoDefault.class)
+
public interface NoDefault{}
可以工作…不要把它看作一个空接口,把它看作一个标记;-)。看,哇,是的,我能做到。我只是使用了实体本身:
@NotEmpty(groups=User.class)