表格注释的注释说明已存在。为此,我们必须使用 Hibernate @Table 注解,与 JPA @Table 注解互补。
例如:
@javax.persistence.Table( name = "Cat" )
@org.hibernate.annotations.Table( comment = "Table for cats" )
public class Cat {
...
关于专栏评论:
似乎没有等价物,即使在 Hibernate 5.2 / JPA 2.1 中也是如此。
很久以前(2007 年)就该主题提交了一个问题,但仍未解决:Support @Comment or column attribute on @Table and @Column。自 2012 年以来被遗弃?
我还在 org.hibernate.dialect.Dialect 中发现了评论用法:
/**
* Does this dialect/database support commenting on tables, columns, etc?
*
* @return {@code true} if commenting is supported
*/
public boolean supportsCommentOn() {
return false;
}
/**
* Get the comment into a form supported for table definition.
*
* @param comment The comment to apply
*
* @return The comment fragment
*/
public String getTableComment(String comment) {
return "";
}
/**
* Get the comment into a form supported for column definition.
*
* @param comment The comment to apply
*
* @return The comment fragment
*/
public String getColumnComment(String comment) {
return "";
}
例如 PostgreSQL81Dialect 支持它(supportsCommentOn() 返回 true)。
它允许使用 SQL 命令“COMMENT ON ...”,
就像在 PostgreSQL (https://www.postgresql.org/docs/current/static/sql-comment.html) 中一样。
例如:
COMMENT ON TABLE my_schema.my_table IS 'Employee Information';
COMMENT ON COLUMN my_table.my_column IS 'Employee ID number';
似乎在那里使用:org.hibernate.tool.schema.internal.StandardTableExporter#getSqlCreateStrings
该列的注释是从使用 org.hibernate.mapping.Column#getComment 的 Hibernate 映射中提取的。
最后,如果使用Hibernate Tools和逆向工程,列的注释是从JDBC DatabaseMetaData中提取的,使用org.hibernate.cfg.reveng.BasicColumnProcessor#processBasicColumns。
-> String comment = (String) columnRs.get("REMARKS");