is there a way how I can get MetaData about my Hibernate Annotations?
I need information about Associations if they are nullable o开发者_Go百科r 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
or CollectionType
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
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):
Annotation[] tabAnnotation = A.class.getField( "fieldB" ).getDeclaredAnnotations( );
for( Annotation annotation : tabAnnotation )
if( annotation instanceof Entity )
System.out.println( ((Entity)annotation).isNullable() );
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).
精彩评论