JPA: How to pass parameters to namedQuery

View: New views
4 Messages — Rating Filter:   Alert me  

JPA: How to pass parameters to namedQuery

by DRy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I defined two named-queries in my orm.xml:

<named-query name="findAll">
    <query>SELECT c FROM Customer c</query>
</named-query>
<named-query name="findByOid">
    <query>SELECT c FROM Customer c WHERE c.oid = :oid</query>
</named-query>

I can use the "findAll" named-query to consume customer-objects

        from("jpa:com.test.entity.Customer?consumer.namedQuery=findAll&delay=10000&consumeLockEntity=true&consumeDelete=true")

but how can I pass parameter(s) to the "findByOid" named-query ... ?

Sorry if this might be a beginner question ...


... DRy

Re: JPA: How to pass parameters to namedQuery

by Claus Ibsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 29, 2009 at 7:43 PM, DRy <dirk.rybinski@...> wrote:

>
> Hi,
>
> I defined two named-queries in my orm.xml:
>
> <named-query name="findAll">
>    <query>SELECT c FROM Customer c</query>
> </named-query>
> <named-query name="findByOid">
>    <query>SELECT c FROM Customer c WHERE c.oid = :oid</query>
> </named-query>
>
> I can use the "findAll" named-query to consume customer-objects
>
>
> from("jpa:com.test.entity.Customer?consumer.namedQuery=findAll&delay=10000&consumeLockEntity=true&consumeDelete=true")
>
> but how can I pass parameter(s) to the "findByOid" named-query ... ?
> :confused:
>
> Sorry if this might be a beginner question ... :working:
> --

See the unit tests of camel-jpa, for example JpaWithNamedQueryTest
It could maybe inspire you.


> View this message in context: http://www.nabble.com/JPA%3A-How-to-pass-parameters-to-namedQuery-tp26118566p26118566.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: JPA: How to pass parameters to namedQuery

by DRy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Claus Ibsen-2 wrote:
> from("jpa:com.test.entity.Customer?consumer.namedQuery=findAll&delay=10000&consumeLockEntity=true&consumeDelete=true")

See the unit tests of camel-jpa, for example JpaWithNamedQueryTest
It could maybe inspire you.
Sorry, but that didn't help at all ...

I want to know how to pass a parameter for a namedQuery-based jpa consume in something like that

from("jpa:com.test.entity.Customer?consumer.namedQuery=findByOid)

where findByOid is defined in my orm.ml

<named-query name="findByOid">
    <query>SELECT c FROM Customer c WHERE c.oid = :oid</query>
</named-query>


... DRy

Re: JPA: How to pass parameters to namedQuery

by Claus Ibsen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 30, 2009 at 9:00 AM, DRy <dirk.rybinski@...> wrote:

>
> Hi,
>
>
> Claus Ibsen-2 wrote:
>>
>>
>>> from("jpa:com.test.entity.Customer?consumer.namedQuery=findAll&delay=10000&consumeLockEntity=true&consumeDelete=true")
>>
>> See the unit tests of camel-jpa, for example JpaWithNamedQueryTest
>> It could maybe inspire you.
>>
>>
>
> Sorry, but that didn't help at all ...
>
> I want to know how to pass a parameter for a namedQuery-based jpa consume in
> something like that
>
> from("jpa:com.test.entity.Customer?consumer.namedQuery=findByOid)
>
> where findByOid is defined in my orm.ml
>
> <named-query name="findByOid">
>    <query>SELECT c FROM Customer c WHERE c.oid = :oid</query>
> </named-query>
>

I dont think you can do it on the consumer side (eg in the from). Use
a fixed value or do something else.
Or create a ticket in JIRA so we can see how we can implemented this in camel.



>
> ... DRy
> --
> View this message in context: http://old.nabble.com/JPA%3A-How-to-pass-parameters-to-namedQuery-tp26118566p26126224.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus