让Hibernate生成的DDL脚本自动增加注释(三)

2014-11-24 09:09:47 · 作者: · 浏览: 6
throw new MappingException(
"Failed to load annotated classes from classpath", ex);
}
}
/**
* Check whether any of the configured entity type filters matches the
* current class descriptor contained in the metadata reader.
*/
private boolean matchesEntityTypeFilter(MetadataReader reader,
MetadataReaderFactory readerFactory) throws IOException {
for (TypeFilter filter : ENTITY_TYPE_FILTERS) {
if (filter.match(reader, readerFactory)) {
return true;
}
}
return false;
}
}
[java]
/**
* $Id:$
*/
package com.share.utils.hibernate;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.cfg.Ejb3Column;
import org.hibernate.mapping.PersistentClass;
import com.share.annotations.Comment;
public class CommentBinder {
public static void bindTableComment(XClass clazzToProcess, PersistentClass persistentClass) {
if (clazzToProcess.isAnnotationPresent(Comment.class)) {
String tableComment = clazzToProcess.getAnnotation(Comment.class).value();
persistentClass.getTable().setComment(tableComment);
}
}
public static void bindColumnComment(XProperty property, Ejb3Column[] columns) {
if (null != columns)
if (property.isAnnotationPresent(Comment.class)) {
String comment = property.getAnnotation(Comment.class).value();
for (Ejb3Column column : columns) {
column.getMappingColumn().setComment(comment);
}
}
}
public static void bindColumnComment(XProperty property, Ejb3Column column) {
if (null != column)
if (property.isAnnotationPresent(Comment.class)) {
String comment = property.getAnnotation(Comment.class).value();
column.getMappingColumn().setComment(comment);
}
}
}
[java
/**
* $Id:$
*/
package com.share.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.TYPE,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Comment {
String value() default "";
}