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. --------------------------------------- | User_id | User_name | User_type | --------------------------------------- | 1 | Mark Taylor | Administrator | | 2 | Bill Paxton. Coordinator | | 3 | Tony Brooke | Administrator | | 4 | Ali Jahan | Developer | ---------------------------------------

I am hoping that the result is ending,

  admin, coordinator, developer  

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:

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

I have seen another example and have tried it along with it,

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

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,

  Administrator, Coordinator, Developer  

What I'm currently doing without this code,

  Administrator, Coordinator, Administrator, Developer  

The above mentioned work is called the following,

  list & lt; Users & gt; UserList = userDao.findDistinctUserType ();  

User is an object that has the following information,

  private INAD; Private string user name; Type Private String User;  

We have that code down and down, where the user object is defined, we,

  @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; }  

Thank you for all your answers. I may be asking more as I go along with the appropriate !!!


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -