facebook

HQL query help

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #302094 Reply

    amir55
    Participant

    hi

    is there any way to convert next query to a string query

    session.createQuery(“from Concert1 c where ? in elements(c.visitors)”).setEntity(0,visitor1).list()

    I want to use findByQuery *String query) to do the job ? rather than the session

    thanks a lot;

    Amir

    #302111 Reply

    support-joy
    Member

    Amir,

    I want to use findByQuery *String query) to do the job ? rather than the session

    Yes,It is possible.There are two ways to do this.
    1. you need to create findByQuery (String query) method in your DAO class.
    2. You need to create another DAO by extending already existing DAO class and create findByQuery (String query) method in newly created DAO class.

    #302117 Reply

    amir55
    Participant

    hi dear Jov

    yes i had this findby as foloows and it works fine but the question about the code.

    public List findByQuery (String queryString) {
    log.debug(“finding all entries of a query “);
    try {
    return getHibernateTemplate().find(queryString) ;
    } catch (RuntimeException re) {
    log.error(“find by property name failed”, re);
    throw re;
    }
    }

    so I just a correct code to the next as a quesryString

    String queryString = “from Concert c where ? in elements(c.visitors)”)).setEntity(0,visitor).list(); // I get error here in syntax

    List list = springDAO.findByQuery(quweyString); // query syntax was wrong

    yours faithfully

    Amir

    #302172 Reply

    Amir,
    The issue is not clear from your post.

    String queryString = “from Concert c where ? in elements(c.visitors)”)).setEntity(0,visitor).list();

    This is certainly a syntax error. The right hand part returns a List object whereas the left hand part is a String.
    The expression should not contain .setEntity(0,visitor).list();
    Can you share your project with us? You can send a mail to support@genuitec.com. Please add ATTN: Shalini in the subject and refer to this thread. This will help us reproduce this issue internally and quickly work on resolution. Thanks for your help

    #302621 Reply

    amir55
    Participant

    hi dear

    I have 2 points :

    1 – how to get MyEclipse show the methods when I point the cursor to right hand side to and press control + space bar. I get message no default proposals why?

    so I need to know more on getHibernateTemplate().findByQuery

    2 – I need to get a String into Query without using session.createQuery as I want to avoid the session as I need to begin transaction and else. The transaction issue is dealt by spring

    many thanks

    #302624 Reply

    amir55
    Participant

    hi sir

    simply can you correct this query for me

    select mf from many_to_any1.ItemObject mf where mf.itemBeanSet.id in ” + “(select hg.id from many_to_any1.ItemBean1 hg where hg.number > 150) ”

    Ialways get illegal attempt to dereference collection

    many thanks really

    Amir

    #302626 Reply

    Amir,
    Its hard to debug from my end.Can you send us your project? You can send a mail to support@genuitec.com. Please add ATTN: Shalini in the subject and refer to this thread. This will help us reproduce this issue internally and quickly work on resolution.
    Please send us the scripts of the tables you are using and the data base details also.

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: HQL query help

You must be logged in to post in the forum log in