简体   繁体   中英

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) ;

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 .

On that class is getResultSet() but is private which would have allowed:

  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?

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

Like suggested in your similar question here: hibernate get underlying sql resutlset. nativequery is very limiting

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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