简体   繁体   English

Hibernate,进行本机 sql 查询并获取 get() 上事物的列名

[英]Hibernate, making a native sql query and getting column names for the things on get()

Given this example:鉴于这个例子:

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

When I do scroll.next() i can do scroll.get(i) ;当我做 scroll.next() 我可以做scroll.get(i)

However, I can not see a way to get the column name that you normally get on a select.但是,我看不到获取通常在选择中获得的列名的方法。 Normally you would on a ResultSet get the columName for i .通常你会在ResultSet获得icolumName

On that class is getResultSet() but is private which would have allowed:在该类上是 getResultSet() 但它是私有的,这将允许:

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

But is now not possible, and not pretty even if it was.但现在不可能了,即使是这样也不漂亮。

If you work with a native query, why don't you use the JDBC API directly?如果您使用本机查询,为什么不直接使用 JDBC API?

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

Like suggested in your similar question here: hibernate get underlying sql resutlset.就像您在这里的类似问题中所建议的那样: hibernate getunderlying sql resutlset。 nativequery is very limiting nativequery 非常有限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM