Results 1 to 3 of 3

Thread: findByValueBean and nested properties

  1. #1

    Default findByValueBean and nested properties

    Can I use nested properties in the named params in my hql query? for example, "from User inner join user.person person where person.firstName = erson.firstName"

    I will pass a User instance as the valueBean to findByNamedQueryAndValueBean. User has a getPerson which returns a Person which has a getFirstName.

    Anyway, unless I'm doing something stupid, my testing shows that nested properties can't be used as named params in the hql. Everything seems fine until it reaches the erson.firstName. I get the following exception during configuration:

    [bill] ERROR [main] ErrorCounter.reportError(35) | *** ERROR: <AST>:0:0: unexpected AST node: :
    [bill] DEBUG [main] ErrorCounter.reportError(28) | <AST>:0:0: unexpected AST node: :
    <AST>:0:0: unexpected AST node: :
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr( HqlSqlBaseWalker.java:829)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExprL hs(HqlSqlBaseWalker.java:4326)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr( HqlSqlBaseWalker.java:752)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlS qlBaseWalker.java:859)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSub query(HqlSqlBaseWalker.java:3713)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.compariso nExpr(HqlSqlBaseWalker.java:3193)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalEx pr(HqlSqlBaseWalker.java:1405)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClau se(HqlSqlBaseWalker.java:599)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(Hql SqlBaseWalker.java:404)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectSta tement(HqlSqlBaseWalker.java:201)
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement (HqlSqlBaseWalker.java:151)
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze( QueryTranslatorImpl.java:189)
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompil e(QueryTranslatorImpl.java:130)
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile( QueryTranslatorImpl.java:83)
    at org.hibernate.impl.SessionFactoryImpl.getQuery(Ses sionFactoryImpl.java:427)
    at org.hibernate.impl.SessionFactoryImpl.checkNamedQu eries(SessionFactoryImpl.java:388)
    at org.hibernate.impl.SessionFactoryImpl.<init>(Sessi onFactoryImpl.java:291)
    at org.hibernate.cfg.Configuration.buildSessionFactor y(Configuration.java:1005)

    If I change erson.lastName to something like :foo then it gets past configuration, but doesn't help me much for what I am trying to do.

    It seems that this would be doable using BeanUtils or OGNL. Is there any implementation like this available in spring or hibernate?

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Your question is hibernate specific so I guess the HB forums are more approapriate for this. AFAIK, named parameters are treated as values not as beans - you should supply an int, long or smth similar and not a tree of objects. A workaround would be to use the nested property directly:

    "WHERE person.firstName = :firstName"
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3

    Default

    find*ValueBean absolutely takes a bean. The underlying code calles Query.setProperties. It seems to limited though in that you can not use nested properties of the bean. It seems that it would relatively easy to make an implementation that use nested properties using BeanUtils or OGNL. The problem is that I can not use named params names that have a "." in them, so I'm out of luck.

    Seems like a reasonable request to allow "." in the named param names, but I can't seem to get the hibernate folks to agree.

    I'm just wondering if anyone has used spring capabilities to accomplish what I am trying to do. The fact that spring has written find*ValueBean methods seems to indicate that someone has given it some thought.

Posting Permissions

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