facebook

Creating a Named Query using DSL does not work

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #317649 Reply

    Peter
    Member

    Hi,

    I am trying to create a Named Query for an object that returns the max of an integer field, but when i create one using DSL it gives me a cannot cast error.

    So…
    -I have a Member object with a memberno field.
    -I createws a named query using DSL and but when had no input and 1 integer output.
    and the named query is

    Select max(myMember.memberno) from Member myMember

    When I save the DAO of the member object i get an error here:

    
        @Transactional
        public Integer getMaxMemberNo(int startResult, int maxRows) throws DataAccessException {
            try {
                return executeQueryByNameSingleResult("getMaxMemberNo");
            } catch (NoResultException nre) {
                return null;
            }
        }
    

    on

    
    return executeQueryByNameSingleResult("getMaxMemberNo");
    

    the error “Type mismatch: cannot convert from Member to Integer” shows.

    Please Help.

    #317725 Reply

    jkennedy
    Member

    Peter,

    Sorry for the inconvenience, this is a defect in the software. The code generator is not correctly determining the fact that your return type is not the Entity type and is emitting code that assumes the return type to be an instance of the Entity for this DAO.

    I am putting a fix in for the 9.1 release expected to be going out next week.

    The work around would be to write a method by hand into your dao interface and impl that uses the super class methods to get a Query object and execute your query.

    The contents of your method would look something like:
    Query query = createQuerySingleResult(“Select max(myMember.memberno) from Member myMember”, (Object[])null);
    return (Integer) query.getSingleResult();

    Sorry about that…
    Thanks,
    Jack

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Creating a Named Query using DSL does not work

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