Hibernate - Using Distinct Select query in Criteria -
Hope you're all right. Well I'm quite new to this stuff being in hibernation and I'm having difficulty finding a selection specific question to work. I am hoping that the result is ending, What am I expecting as a return statement user - A list of types, the type of function I have written after searching for help is as follows: I have seen another example and have tried it along with it, But for strange reason, it has always been unsuccessful and I am not getting through, if you can provide me a good solution, then it would be great. Looking forward to your help Edit I hope the output is as follows, What I'm currently doing without this code, The above mentioned work is called the following, User is an object that has the following information, We have that code down and down, where the user object is defined, we, Thank you for all your answers. I may be asking more as I go along with the appropriate !!! --------------------------------------- | User_id | User_name | User_type | --------------------------------------- | 1 | Mark Taylor | Administrator | | 2 | Bill Paxton. Coordinator | | 3 | Tony Brooke | Administrator | | 4 | Ali Jahan | Developer | ---------------------------------------
admin, coordinator, developer
public list & lt; Users & gt; FindDistinctUserType () throws HibernateException {criteria c = this.createCriteria (); C.setProjection (Projections.distinct (Projections.property ("user_type")); Return (List & lt; User & gt;) (Users) c.uniqueResult (); }
public list & lt; Users & gt; FindDistinctUserType () throws HibernateException {criteria c = this.createCriteria (); Launch list projection list = projection Projection list (); Projection List Projection List 2 = Projection Projection list (); Projection ("user-type"), "user-type"));). C.setProjection (projectionList2); C.setResultTransformer (Transformers.aliasToBean (User.class)); Return (List & lt; User & gt;) (Users) c.uniqueResult (); }
Administrator, Coordinator, Developer
Administrator, Coordinator, Administrator, Developer
list & lt; Users & gt; UserList = userDao.findDistinctUserType ();
private INAD; Private string user name; Type Private String User;
@Column (name = "user_type", nullable = false ) Public string getUserType () {return userType; Thanks for all your feedback, I was able to solve the problem. According to your suggestion, I did this and it worked for me,
public list & lt; String & gt; FindDistinctUserName () throws HibernateException {list & lt; String & gt; ReturnVal = New Arrestist & lt; String & gt; (); Criterion c = this.createCriteria (); C.setProjection (Projections.distinct (Projections.property ("User Type"))); C.addOrder (Order.asc ("user type")); & Lt; String & gt; UserTypeList = c.list (); (String user-typed: user type list) for {if user! Type. Type a couple ("")) {returnVal.add (userType); }} Return return value; }
Comments
Post a Comment