有没有办法让我得到关于我的Hibernate Annotations的MetaData?
我需要关联的信息,如果它们可以为空。
现在我只能查询ClassMetadata
http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/metadata/ClassMetadata.html
我可以浏览属性并检查它是否为
EntityType
http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/type/EntityType.html
或CollectionType
http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/type/CollectionType.html
EntityType
显然有isNullable
个功能但不是CollectionType
所以我考虑使用注释信息
@GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "seizureI18n"))
@Id
@GeneratedValue(generator = "generator")
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
这是可能的,也可能是实现我想要的另一种方式。
此致
JS
答案 0 :(得分:2)
根据定义,集合不能为空。 n个元素的集合意味着有n个指定类型的实体具有对该实体的外键引用。它并不意味着该实体的表格中有任何内容。
因此,您可以检查可空性的唯一关系是* ToOne-relations(OneToOne,ManyToOne)。
答案 1 :(得分:2)
我不确定我理解你的问题,但如果你想看看是否存在注释,你可以这样做(使用内省):
Annotation[] tabAnnotation = A.class.getField( "fieldB" ).getDeclaredAnnotations( );
for( Annotation annotation : tabAnnotation )
if( annotation instanceof Entity )
System.out.println( ((Entity)annotation).isNullable() );