我有一个对象类,除了Id之外没有必填字段。这是代码:
Entity
@XmlRootElement
@Table(name = "T_HOST_SPEC")
@Cacheable(false)
@NamedQueries({
@NamedQuery(name = HostSpec.FIND_ALL, query = "SELECT m FROM HostSpec m")
,@NamedQuery(name = HostSpec.FIND_BY_IP_CONTEXT_PATH_PORT, query = "SELECT m FROM HostSpec m WHERE m.ip = :ip AND m.contextPath =:contextPath AND m.port =:port ")})
public class HostSpec extends AbstractEntity {
@Id
@SequenceGenerator(name = "HOST_SPEC_SEQUENCE_GENERATOR", sequenceName = "HOST_SPEC_SEQ", initialValue = 1, allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HOST_SPEC_SEQUENCE_GENERATOR")
@XmlElement(name = "id")
@NotNull
@Column(name = "ID", nullable = false)
private Long id;
@Size(max =200 )
@Column(name = "APP_NAME",length = 25)
@XmlElement(name = "APP_NAME")
private String appName;
@Size(max =1000 )
@Column(name = "APP_SERVER_INFO",length = 25)
@XmlElement(name = "APP_SERVER_INFO")
private String serverInfo;
@Size(max =100 )
@Column(name = "CONTEXT_PATH",length = 25)
@XmlElement(name = "CONTEXT_PATH")
private String contextPath;
@Size(max =255 )
@Column(name = "BUILD_DATE",length = 25)
@XmlElement(name = "BUILD_DATE")
private String buildDate;
@Size(max =4000 )
@Column(name = "DESCRIPTION",length = 25)
@XmlElement(name = "DESCRIPTION")
private String description;
@Size(max =50 )
@Column(name = "IP",length = 25)
@XmlElement(name = "IP")
private String ip;
@Size(max =200 )
@Column(name = "MODULE_NAME",length = 25)
@XmlElement(name = "MODULE_NAME")
private String moduleName;
@Size(max =100 )
@Column(name = "NAME",length = 25)
@XmlElement(name = "NAME")
private String name;
@Size(max = 10)
@XmlElement(name = "PORT")
@Column(name = "PORT")
private Long port;
@Size(max =20 )
@Column(name = "PROTOCOL",length = 25)
@XmlElement(name = "PROTOCOL")
private String protocol;
@Size(max = 10)
@XmlElement(name = "VERSION_CODE")
@Column(name = "VERSION_CODE")
private Long versionCode;
@Size(max =100 )
@Column(name = "VERSION_NAME",length = 25)
@XmlElement(name = "VERSION_NAME")
private String versionName;
@Size(max =100 )
@Column(name = "VIRTUAL_SERVER_NAME",length = 25)
@XmlElement(name = "VIRTUAL_SERVER_NAME")
private String serverName;
//getters & setters
当我尝试运行它时,抛出此异常: javax.validation.UnexpectedTypeException:HV000030:找不到类型的验证程序:java.lang.Long 请帮忙
答案 0 :(得分:2)
@Size
不适用于Long
类型(在这种情况下,您应使用@Max
。)
因此,您应该使用字段@Size(max = 10)
和@Max
上的相应port
注释替换versionCode
根据javadoc,@Size
可用于以下类型: