完美解决hibernatetool oracle注释问题
我的模板工具一直不能完美的将oracle的注释生成到我的代码中,
失眠时解决了这个问题,记录下供大家参考
不知道是不是我的hibernatetool比较旧有这个问题
配置hibernatetool.metadatadialect=org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect决定代码使用OracleMetaDataDialect获取数据库表结构
否则使用jdbc方式,这样是不能得到commont的
修改OracleMetaDataDialect类的2个方法
所以大家可以看到人家压根就没有实现oracle获取注释的功能呢
[java]
public Iterator getTables(final String catalog, final String schema, String table) {
final StringBuffer query = new StringBuffer();
try {
log.debug("getTables(" + catalog + "." + schema + "." + table + ")");
// Collect both Tables and Views from the 'ALL' data dicitonary tables.
// Note: This will potentally collect more tables that the jdbc meta data
Statement stmt = this.getConnection().createStatement();
query.append("select t.*,tc.comments as REMARKS from ( ");
query.append("select table_name, owner, 'TABLE' from all_tables ");
if (schema != null || table != null)
query.append("where ");
if (schema != null) {
query.append("owner='" + schema + "' ");
}
if (table != null) {
if (schema != null)
query.append("and ");
query.append("table_name = '" + table + "' ");
}
query.append("union all ");
query.append("select view_name, owner, 'VIEW' from all_views ");
if (schema != null || table != null)
query.append("where ");
if (schema != null) {
query.append("owner='" + schema + "' ");
}
if (table != null) {
if (schema != null)
query.append("and ");
query.append("view_name = '" + table + "' ");
}
query.append(" )t ");
query.append(" ,USER_TAB_COMMENTS tc where t.table_name=tc.table_name ");
if (log.isDebugEnabled())
log.debug("getTables Query:" + query.toString());
ResultSet tableRs = stmt.executeQuery(query.toString());
return new ResultSetIterator(stmt, tableRs, getSQLExceptionConverter()) {
Map element = new HashMap();
protected Object convertRow(ResultSet tableRs) throws SQLException {
element.clear();
element.put("TABLE_NAME", tableRs.getString(1));
element.put("TABLE_SCHEM", tableRs.getString(2));
element.put("TABLE_CAT", null);
element.put("TABLE_TYPE", tableRs.getString(3));
element.put("REMARKS", tableRs.getString("REMARKS"));
return element;
}
protected Throwable handleSQLException(SQLException e) {
// schemaRs and catalogRs are only used for error reporting if
// we get an exception
String databaseStructure = getDatabaseStructure( catalog, schema );
throw getSQLExceptionConverter().convert( e,
"Could not get list of tables from database. Probably a JDBC driver problem. "+query.toString()
+ databaseStructure, null );
}
};
} catch (SQLException e) {
// schemaRs and catalogRs are only used for error reporting if we get an exception
String databaseStructure = getDa
补充:软件开发 , Java ,