开发者

insert into .. select in HQL causes MismatchedTreeNodeException

I'm trying to do what seems like a pretty straightforward insert into .. select with HQL, but I am stumped by a MismatchedTreeNodeException. As far as I can tell, I'm the first person in the world to encounter this, which I take as an indication that I'm doing something very silly :).

session.CreateQuery(
    @"insert into PriceValue (Currency, Price, Value)
    select :destinationCurrency, p, pv.Value * :x
    from PriceValue pv
    where pv.Currency = :defaultCurrency" )
    .SetDecimal( "x", x )
    .SetEntity( "destinationCurrency", currency )
    .SetEntity( "defaultCurrency", Config.DefaultCurrency )
    .ExecuteUpdate();

The goal of this exercise is to add price values in a newly created currency to all existing prices.

The exception is:

QuerySyntaxException: Exception of type 'Antlr.Runtime.MismatchedTreeNodeException' was thrown. near line 1, column 63 [insert into PriceValue (Currency, AcmeCorp.Core.Models.Products.Price, Value) select :destinationCurrency, pv.Price, pv.Value * :x from AcmeCorp.Core.Models.Products.PriceValue pv where pv.Currency = :defaultCurrency]

One hint may be that it expands part of the pr开发者_如何学运维operty specification (Price -> AcmeCorp.Core.Models.Products.Price) -- the exception message seems to indicate a problem near ..Products.Price.

The (trimmed-down) mappings (generated by Castle ActiveRecord) are:

<class name="AcmeCorp.Core.Models.Products.Price, AcmeCorp.Core.Models" table="`price`" schema="`products`">
    <id name="Id" access="property" column="`price_id`" type="Int32" unsaved-value="0">
        <generator class="native"></generator>
    </id>
    <set name="Values" access="nosetter.camelcase" table="`price_value`" lazy="false" inverse="true" cascade="all" fetch="join" batch-size="1000">
        <key column="`price_id`" />
        <one-to-many class="AcmeCorp.Core.Models.Products.PriceValue, AcmeCorp.Core.Models" />
    </set>
</class>

<class name="AcmeCorp.Core.Models.Products.PriceValue, AcmeCorp.Core.Models" table="`price_value`" schema="`products`">
    <id name="Id" access="property" column="`price_value_id`" type="Int32" unsaved-value="0">
        <generator class="native"></generator>
    </id>
    <property name="Value" access="property" type="System.Decimal">
        <column name="`value`"/>
    </property>
    <many-to-one name="Currency" access="property" class="AcmeCorp.Core.Models.Common.Currency, AcmeCorp.Core.Models" column="`currency_code`" unique-key="uk_price_currency" lazy="proxy" />
    <many-to-one name="Price" access="property" class="AcmeCorp.Core.Models.Products.Price, AcmeCorp.Core.Models" column="`price_id`" unique-key="uk_price_currency" lazy="proxy" />
</class>

Any ideas?


I think the :x is causing the MismatchedTreeNodeException, I dont think hql will allow a param within the select. Try replacing it with a constant and see if helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜