使用Spring Data JPA+hibernate持久化对象时报异常 80
异常描述:javax.validation.UnexpectedTypeException:HV000030:Novalidatorcouldbefoundfortype...
异常描述:javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Integer.
保存一个User对象
User类
@Entity
@Table(name="t_front_user")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="com.jxufe.oec.entity.main.User")
public class User implements Idable<Long> {
public static final Integer STATUS_DISABLED = 0;
public static final Integer STATUS_ENABLED = 1;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotBlank
@Length(max=32)
@Column(length=32, nullable=true)
private String realname;
@NotBlank
@Length(max=32)
@Column(length=32, nullable=false, unique=true, updatable=false)
private String username;
@Column(length=64, nullable=false)
private String password;
@Transient
private String plainPassword;
@Column(length=32, nullable=false)
private String salt;
@Length(max=32)
@Column(length=32)
private String phone;
@Email
@Length(max=128)
@Column(length=128)
private String email;
/**
* 使用状态disabled,enabled
*/
@NotNull
@Length(max=16)
@Column(length=16, nullable=false)
private Integer status = STATUS_ENABLED;
/**
* 帐号创建时间
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(updatable=false)
private Date createTime;
测试方法
User user=new User();
user.setUsername("zxw2476");
user.setPassword("123456");
user.setRealname("张三");
user.setPhone("18720085474");
user.setEmail("1414628406@qq.com");
user.setStatus(0);
user.setCreateTime(new Date());
userService.saveOrUpdate(user);
错误定位在最后保存方法中 展开
保存一个User对象
User类
@Entity
@Table(name="t_front_user")
@Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="com.jxufe.oec.entity.main.User")
public class User implements Idable<Long> {
public static final Integer STATUS_DISABLED = 0;
public static final Integer STATUS_ENABLED = 1;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@NotBlank
@Length(max=32)
@Column(length=32, nullable=true)
private String realname;
@NotBlank
@Length(max=32)
@Column(length=32, nullable=false, unique=true, updatable=false)
private String username;
@Column(length=64, nullable=false)
private String password;
@Transient
private String plainPassword;
@Column(length=32, nullable=false)
private String salt;
@Length(max=32)
@Column(length=32)
private String phone;
@Length(max=128)
@Column(length=128)
private String email;
/**
* 使用状态disabled,enabled
*/
@NotNull
@Length(max=16)
@Column(length=16, nullable=false)
private Integer status = STATUS_ENABLED;
/**
* 帐号创建时间
*/
@Temporal(TemporalType.TIMESTAMP)
@Column(updatable=false)
private Date createTime;
测试方法
User user=new User();
user.setUsername("zxw2476");
user.setPassword("123456");
user.setRealname("张三");
user.setPhone("18720085474");
user.setEmail("1414628406@qq.com");
user.setStatus(0);
user.setCreateTime(new Date());
userService.saveOrUpdate(user);
错误定位在最后保存方法中 展开
1个回答
2015-05-19
展开全部
@NotNull
@Length(max=16)
@Column(length=16, nullable=false)
private Integer status = STATUS_ENABLED;
integer 类型没有这种校验类型,所以错了。
@Length(max=16)
@Column(length=16, nullable=false)
private Integer status = STATUS_ENABLED;
integer 类型没有这种校验类型,所以错了。
追问
那是不是应该去掉@NotNull注解?
追答
@notnull 和@length都去掉。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询