Announcement Announcement Module
No announcement yet.
findByValueBean and nested properties Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExprL hs(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlS
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSub query(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.compariso nExpr(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalEx pr(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClau se(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(Hql
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectSta tement(
    at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement (
    at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(
    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompil e(
    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(
    at org.hibernate.impl.SessionFactoryImpl.getQuery(Ses
    at org.hibernate.impl.SessionFactoryImpl.checkNamedQu eries(
    at org.hibernate.impl.SessionFactoryImpl.<init>(Sessi
    at org.hibernate.cfg.Configuration.buildSessionFactor y(

    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
    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"


    • #3
      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.