java - Get single ScrollableResults row -


i trying extract count(*) matching predicates. every time use createsqlquery, find myself having write code along lines of,

// skipped code query q = session.createsqlquery("select count(*) id=1"); scrollable results = q.scroll();  while ( results.next() ) {     object[] row = object[] results.get();     // assign     string str = row[0];     //set , persist }   

i have many such queries unioned on single transaction. how single result here? missing something?

you can use method instead:

object[] row = (object[]) query.uniqueresult(); 

if query returns more 1 result, method throw exception

edit:

on top of that, use resulttransformer convert object[] integer. remove need result array , extract it's first entry. see example more info


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -