我找到了自己问题的答案.
我不确定是否可以?它适用于所有数据库吗?
肯定它适用于mysql.
这是工作代码:
@Column(columnDefinition=" INT(11) NOT NULL COMMENT '0 for no action, 1 for executed, 2 for validated, 3 for aproved'")
private int status;
Run Code Online (Sandbox Code Playgroud)
表注释的注释描述已存在。为此,我们必须使用 Hibernate @Table 注释,与 JPA @Table 注释互补。
例如 :
@javax.persistence.Table( name = "Cat" )
@org.hibernate.annotations.Table( comment = "Table for cats" )
public class Cat {
...
Run Code Online (Sandbox Code Playgroud)
关于该专栏的评论:即使在 Hibernate 5.2 / JPA 2.1 中,似乎也没有等价物。
很久以前(2007 年)就这个主题提交了一个问题,但仍未解决:支持 @Table 和 @Column 上的 @Comment 或列属性。自 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 "";
}
Run Code Online (Sandbox Code Playgroud)
例如 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';
Run Code Online (Sandbox Code Playgroud)
它似乎在那里使用:org.hibernate.tool.schema.internal.StandardTableExporter#getSqlCreateStrings
该列的注释是从带有org.hibernate.mapping.Column#getComment的 Hibernate Mapping 中提取的。
最后,如果使用Hibernate Tools和逆向工程,则列的注释是从 JDBC DatabaseMetaData 中提取的,使用org.hibernate.cfg.reveng.BasicColumnProcessor#processBasicColumns。
-> String comment = (String) columnRs.get("REMARKS");
Run Code Online (Sandbox Code Playgroud)
您可以使用@Comment注释。
该注解是在hibernate 5.6.02021-09-21 发布的版本中引入的,并且Spring Boot 2.6(2021-11-17 发布)使用的是 Hibernate 5.6
https://hibernate.atlassian.net/browse/HHH-4369\ https://github.com/hibernate/hibernate-orm/pull/3611
@Entity(name = "Person")
@javax.persistence.Table(name = TABLE_NAME)
@org.hibernate.annotations.Table(comment = TABLE_COMMENT, appliesTo = TABLE_NAME)
public static class TestEntity {
@Id
@GeneratedValue
@Comment("I am id")
private Long id;
@Comment("I am name")
@javax.persistence.Column(length = 50)
private String name;
@ManyToOne
@JoinColumn(name = "other")
@Comment("I am other")
private TestEntity other;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11789 次 |
| 最近记录: |