Tit*_*ito 6 java annotations duplicates aggregation
我有多个类,我总是在定义表的主键的字段上使用相同的注释,例如:
@Id
@Type(type = "uuid-binary")
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2",
parameters = { @Parameter(
name = "uuid_gen_strategy_class",
value = "org.hibernate.id.UUIDGenerationStrategy")
})
@Column(name="PROFILE_ID", unique = true)
@NotNull(message = "we have one message" , payload =Severity.Info.class)
private UUID profileId;
Run Code Online (Sandbox Code Playgroud)
现在我正在寻找一种方法,在我进行验证时将所有这些注释聚合到一个单独的注释,比如注释聚合,即我可以将@NotNull和@Size从(javax.validation.constraints)聚合到以下注释"Name" .
package org.StudentLib.CustomeAnnotations;
import …
@Target( {FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
@Constraint(validatedBy = {})
@Documented
@NotNull
@Id
@Size(message = "The size of the name should be between {min} and {max} caracters",
min = 1, max = 50,
payload = Severity.Info.class
)
public @interface Name {
}
Run Code Online (Sandbox Code Playgroud)
那么我如何对持久性注释做同样的事情,我总是得到
此位置不允许使用注释@Id
为什么我收到此错误?有没有办法将持久性注释和验证注释组合在一个注释中.我问这个的原因是因为我的代码中有大约40个表(实体),每次我需要定义该表的主键时,我觉得我是代码重复.
| 归档时间: |
|
| 查看次数: |
926 次 |
| 最近记录: |