Hibernate 注解元数据
有没有办法获取有关我的 Hibernate 注释的元数据?
我需要有关关联的信息(如果它们可为空)。
现在我只能查询 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
is there a way how I can get MetaData about my Hibernate Annotations?
I need information about Associations if they are nullable or not.
Right now I can only query for ClassMetadata
http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/metadata/ClassMetadata.html
Where I can run through the properties and check if it is a
EntityType
http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/type/EntityType.html
or CollectionType
http://docs.jboss.org/hibernate/core/3.5/javadocs/org/hibernate/type/CollectionType.html
EntityType
apparently has a isNullable
function but not CollectionType
So I thought about using the Annotation information
@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;
}
Is this possible or maybe another way to achieve what I want.
Regards
JS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否理解你的问题,但如果你想查看注释是否存在,你可以这样做(使用内省):
I am not sure I understand your question, but if you want to see if an annotation is present you could do like this (using introspection):
根据定义,集合不能为空。 n 个元素的集合意味着有 n 个指定类型的实体具有对该实体的外键引用。它并不暗示该实体表中的任何内容。
因此,您可以检查可空性的唯一关系是 *ToOne 关系(OneToOne、ManyToOne)。
A collection can't be nullable, by definition. A collection of n elements means there are n entities of the specified type that have a foreign key reference to this entity. It does not imply anything in this entity's table.
So the only relations you can check for nullability are *ToOne-relations (OneToOne, ManyToOne).