【问题标题】:Hibernate, making a native sql query and getting column names for the things on get()Hibernate,进行本机 sql 查询并获取 get() 上的内容的列名
【发布时间】:2020-10-01 17:49:53
【问题描述】:

举个例子:

    NativeQuery query = query();
    try ( ScrollableResults scroll = query.scroll(ScrollMode.FORWARD_ONLY) ) {
        int i = -1; while ( scroll.next() ) {
            ++i; // DO SOMETHING
        }
    }

当我做 scroll.next() 我可以做 scroll.get(i);

但是,我看不到获取通常在选择时获得的列名的方法。通常,您会在 ResultSet 上为 i 获取 columName

在那个类上是 getResultSet() 但它是允许的:

  scroll.getResultSet().getMetaData().getColumnName(i)

但现在不可能了,即使是这样也不漂亮。

【问题讨论】:

    标签: java sql hibernate


    【解决方案1】:

    如果您使用原生查询,为什么不直接使用 JDBC API?

    session.doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
        }
    });
    

    就像您在此处的类似问题中建议的那样:hibernate get underlying sql resutlset. nativequery is very limiting

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2017-04-14
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多