You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Chris Wolf <cw...@gmail.com> on 2013/01/21 18:11:57 UTC

How to do conditional entity persistence in JPA Consumer

I recently changed a schema to be more normalized by factoring out a
column of type varchar2 that takes one of only a few dozen, but long
values,
so I created a lookup table for these strings and replaced the
sting-valued column in the main entity with a foreign-key valued
column, referencing
the lookup table.

So now when I persist the main entity, I need to perform a lookup in
the string lookup table and only create a new lookup entity if there's
no entry, otherwise
set the main entity's lookup ref to the PK of the found, matched
string.  How can I do this in the jpa producer without introducing
EntityManager/Query code
in the entity or some pre-processing bean?

Thanks,


Chris

Re: How to do conditional entity persistence in JPA Consumer

Posted by Chris Wolf <cw...@gmail.com>.
Thank you for the advice!

On Mon, Jan 21, 2013 at 4:55 PM, Christian Müller
<ch...@gmail.com> wrote:
> Yes. You can set up your EntityManager using Spring/Blueprint and inject it
> into your bean. In your bean you can use the EntityManager to
> query/update/create entities.
> IMO, it's simpler to do it in this way instead of modeling a Camel route
> which query the database first, use a CBR to route the message and
> update/create an entity.
>
> Best,
> Christian
>
> On Mon, Jan 21, 2013 at 8:56 PM, Chris Wolf <cw...@gmail.com> wrote:
>
>> Hello Christian,
>>
>> So forget about the "jpa:" endpoint and just do the persistence and
>> conditional logic, including
>> getting the EntityManager within the bean?
>>
>> Thanks,
>>
>>     -Chris
>>
>> On Mon, Jan 21, 2013 at 1:42 PM, Christian Müller
>> <ch...@gmail.com> wrote:
>> > I would do this all together in a single bean...
>> >
>> > Best,
>> > Christian
>> >
>> > Sent from a mobile device
>> > Am 21.01.2013 18:12 schrieb "Chris Wolf" <cw...@gmail.com>:
>> >
>> >> I recently changed a schema to be more normalized by factoring out a
>> >> column of type varchar2 that takes one of only a few dozen, but long
>> >> values,
>> >> so I created a lookup table for these strings and replaced the
>> >> sting-valued column in the main entity with a foreign-key valued
>> >> column, referencing
>> >> the lookup table.
>> >>
>> >> So now when I persist the main entity, I need to perform a lookup in
>> >> the string lookup table and only create a new lookup entity if there's
>> >> no entry, otherwise
>> >> set the main entity's lookup ref to the PK of the found, matched
>> >> string.  How can I do this in the jpa producer without introducing
>> >> EntityManager/Query code
>> >> in the entity or some pre-processing bean?
>> >>
>> >> Thanks,
>> >>
>> >>
>> >> Chris
>> >>
>>
>
>
>
> --

Re: How to do conditional entity persistence in JPA Consumer

Posted by Christian Müller <ch...@gmail.com>.
Yes. You can set up your EntityManager using Spring/Blueprint and inject it
into your bean. In your bean you can use the EntityManager to
query/update/create entities.
IMO, it's simpler to do it in this way instead of modeling a Camel route
which query the database first, use a CBR to route the message and
update/create an entity.

Best,
Christian

On Mon, Jan 21, 2013 at 8:56 PM, Chris Wolf <cw...@gmail.com> wrote:

> Hello Christian,
>
> So forget about the "jpa:" endpoint and just do the persistence and
> conditional logic, including
> getting the EntityManager within the bean?
>
> Thanks,
>
>     -Chris
>
> On Mon, Jan 21, 2013 at 1:42 PM, Christian Müller
> <ch...@gmail.com> wrote:
> > I would do this all together in a single bean...
> >
> > Best,
> > Christian
> >
> > Sent from a mobile device
> > Am 21.01.2013 18:12 schrieb "Chris Wolf" <cw...@gmail.com>:
> >
> >> I recently changed a schema to be more normalized by factoring out a
> >> column of type varchar2 that takes one of only a few dozen, but long
> >> values,
> >> so I created a lookup table for these strings and replaced the
> >> sting-valued column in the main entity with a foreign-key valued
> >> column, referencing
> >> the lookup table.
> >>
> >> So now when I persist the main entity, I need to perform a lookup in
> >> the string lookup table and only create a new lookup entity if there's
> >> no entry, otherwise
> >> set the main entity's lookup ref to the PK of the found, matched
> >> string.  How can I do this in the jpa producer without introducing
> >> EntityManager/Query code
> >> in the entity or some pre-processing bean?
> >>
> >> Thanks,
> >>
> >>
> >> Chris
> >>
>



--

Re: How to do conditional entity persistence in JPA Consumer

Posted by Chris Wolf <cw...@gmail.com>.
Hello Christian,

So forget about the "jpa:" endpoint and just do the persistence and
conditional logic, including
getting the EntityManager within the bean?

Thanks,

    -Chris

On Mon, Jan 21, 2013 at 1:42 PM, Christian Müller
<ch...@gmail.com> wrote:
> I would do this all together in a single bean...
>
> Best,
> Christian
>
> Sent from a mobile device
> Am 21.01.2013 18:12 schrieb "Chris Wolf" <cw...@gmail.com>:
>
>> I recently changed a schema to be more normalized by factoring out a
>> column of type varchar2 that takes one of only a few dozen, but long
>> values,
>> so I created a lookup table for these strings and replaced the
>> sting-valued column in the main entity with a foreign-key valued
>> column, referencing
>> the lookup table.
>>
>> So now when I persist the main entity, I need to perform a lookup in
>> the string lookup table and only create a new lookup entity if there's
>> no entry, otherwise
>> set the main entity's lookup ref to the PK of the found, matched
>> string.  How can I do this in the jpa producer without introducing
>> EntityManager/Query code
>> in the entity or some pre-processing bean?
>>
>> Thanks,
>>
>>
>> Chris
>>

Re: How to do conditional entity persistence in JPA Consumer

Posted by Christian Müller <ch...@gmail.com>.
I would do this all together in a single bean...

Best,
Christian

Sent from a mobile device
Am 21.01.2013 18:12 schrieb "Chris Wolf" <cw...@gmail.com>:

> I recently changed a schema to be more normalized by factoring out a
> column of type varchar2 that takes one of only a few dozen, but long
> values,
> so I created a lookup table for these strings and replaced the
> sting-valued column in the main entity with a foreign-key valued
> column, referencing
> the lookup table.
>
> So now when I persist the main entity, I need to perform a lookup in
> the string lookup table and only create a new lookup entity if there's
> no entry, otherwise
> set the main entity's lookup ref to the PK of the found, matched
> string.  How can I do this in the jpa producer without introducing
> EntityManager/Query code
> in the entity or some pre-processing bean?
>
> Thanks,
>
>
> Chris
>