Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

java - can I specify the return type in the hql words -


hi: using hibernate3.6,i meet problem when querying.

take hql exmaple:

string hql="select count(distinct ip),sum(bytes) entity en .... query q=session.createquery(hql); list<?> list=q.list(); 

now can retrive columen properties list following way:

    string[] properties={"count","sum"};     (object obj : list) {             map<string, object> m = new hashmap<string, object>();             object[] props = (object[]) obj;             if(properties.length!=props.length) throw ....             (int = 0; < props.length; i++) {                 m.put(properties[i], props[i]);             }     } 

now,my problem that,when hql result no set,the count 0,but sum null. want 0 also.

of course,i can converting explicitly if know column name , type(they count,sum in above example) of result table db,but did not know.

that's say,i can not use this:

if(props[i]=null) props[i]=0; m.put(properties[i], props[i]); 

since type of props[i] may string,in case if its value null, should "".

so wonder if can sepcify converting type in hql words? maybe someting this:

select count(distinct ip), (long) sum(bytes) entity en ....

select count(distinct ip),(converet ..sum(bytes)) entity en ....

is possible?

bwt,i use mysql 5.1.

thanks.

update: @zinan.yumak:

your answer seems this;

select new wrapper(count(distinct ip),sum(bytes)) entity en where... 

if have create enougth extra class wrapper since there many types of select in appliction.like:

select new anotherwrapper(broswer,count(distinct brower)) entity en where...  ...... 

i think need result transformer. create model class query. add null checks or other checks setter methods. this,

string hql="select count(distinct ip) ip, sum(bytes) bytes entity en .... query q=session.createquery(hql).setresulttransformer(transformers.aliastobean(model.class)); 

and in model class,

class model {     private string ip = "";     private bigdecimal bytes = bigdecimal.zero;      public void setip(string anip) {         if ( astring != null) {             this.ip = anip;         }     }         public void setbytes(string abyte) {         if ( abyte != null) {             this.byte = abyte;         }     }        .     .     . } 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -