Results 1 to 1 of 1
  1. #1
    wonderbiker is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default Help query with hibernate

    Hi to all,
    I have this java code with hibernate:

    Session s = HibernateUtil.currentSession();
    s.clear();
    ArrayList<MyObjectObj> result = new ArrayList();
    Criteria crit = s.createCriteria(MyObjectObjclass);
    if((date1!=null)&&(!date1.toString().trim().equals (""))&&(date2!=null)&&(!date2.toString().trim().eq uals("")) ){
    crit.add(Restrictions.between("data",date1,date2 ));
    }

    crit.add(Restrictions.eq("objectType", "anObjectType"));
    if((myObject.getCodObject()!=null)&&(!myObject.get CodObject().toString().trim().equals(""))){
    crit.add(Restrictions.eq("codObject", myObject.getCodObject()));
    }
    ProjectionList proList = Projections.projectionList();

    if(myObject.getObjectType()!=null){
    proList.add(Projections.groupProperty("object_type "));
    }
    if(myObject.getTotalSmiles()!=null){
    proList.add(Projections.sum("totalSmiles"),"totalS miles");
    }

    crit.setProjection(proList);
    result.addAll(crit.list());
    return result;




    But, the sql that results from the code is something like
    "SELECT FROM TABLENAME ..."
    generating errors and not
    "SELECT this._field1, this._filed2 ... FROM TABLENAME ...".


    The cause seem to be the code lines:


    "if(myObject.getObjectType()!=null){
    proList.add(Projections.groupProperty("object_type "));
    }
    if(myObject.getTotalSmiles()!=null){
    proList.add(Projections.sum("totalSmiles"),"totalS miles");
    }
    "
    beacause it works fine without those code lines.
    I'm newbie with Hibernate query java configuration.
    Any ideas?
    Thanks in advance.
    Last edited by wonderbiker; 04-14-2009 at 11:17 AM.

Similar Threads

  1. Sql Query
    By Nomad in forum JDBC
    Replies: 16
    Last Post: 02-20-2009, 01:58 PM
  2. Hibernate sql query
    By taicode in forum JDBC
    Replies: 0
    Last Post: 03-25-2008, 04:17 PM
  3. Replies: 0
    Last Post: 03-12-2008, 02:23 PM
  4. Using sql:query tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-14-2008, 09:31 AM
  5. Replies: 2
    Last Post: 06-30-2007, 03:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •