我正在使用 eclipse juno 的 Hiberate Tool 插件来生成映射 DB 表的 java bean
它创建 java 文件(例如):
@Entity
@Table(name = "ACTIVITIES")
public class Activities implements java.io.Serializable {
private ActivitiesId id;
private String title;
@EmbeddedId
@AttributeOverrides({
@AttributeOverride(name = "id", column = @Column(name = "id", nullable = false)),
@AttributeOverride(name = "codiceCreatore", column = @Column(name = "codice_creatore", nullable = false))
})
public SynchActivitiesDTOId getId() {
return this.id;
}
public void setId(SynchActivitiesDTOId id) {
this.id = id;
}
@Column(name = "title", nullable = false)
public String getTitle() {
return this.title;
}
public void setTitolo(String title) {
this.title = title;
}
}
我希望它在属性或 get 方法上也写 @NotNull 注释:
@Entity
@Table(name = "ACTIVITIES")
public class Activities implements java.io.Serializable {
@NotNull
private ActivitiesId id;
@NotNull
private String title;
...
}
我尝试编辑 Ejb3PropertyGetAnnotation.ftl(在 C:\Program Files\eclipse\plugins\org.hibernate.eclipse.libs_3.4.0.v20120611-2017-H93-Final\lib\tools\hibernate-tools.jar\pojo 中)添加
<#if !property.optional>
@${pojo.importType("org.hibernate.validator.NotNull")}
</#if>
但是Activities.java中没有变化
我该怎么办?
提前致谢
编辑:我试图修改 C:\Program Files\eclipse\plugins\org.hibernate.eclipse.libs_3.4.0.v20120611-2017-H93-Final\lib\tools\hibernate-tools.jar\pojo\PojoFields
<#foreach field in pojo.getAllPropertiesIterator()><#if pojo.getMetaAttribAsBool(field, "gen-property", true)> <#if pojo.hasMetaAttribute(field, "field-description")> /**
${pojo.getFieldJavaDoc(field, 0)}
*/
</#if> ${pojo.getFieldModifiers(field)} ${pojo.getJavaTypeName(field, jdk5)} ${field.name}<#if pojo.hasFieldInitializor(field, jdk5)> = ${pojo.getFieldInitialization(field, jdk5)}</#if>;
</#if>
+ <#if !field.optional>@${pojo.importType("org.hibernate.validator.NotNull")}</#if>
</#foreach>
但没有任何改变。