You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Borut Bolčina <bo...@gmail.com> on 2012/04/03 08:03:04 UTC

Re: Updating database records with Java DSL JPA component

Hi,

after accepting the fact that I won't be having nice integer primary keys
and instead use some unique value from XML fragment (which in turn becomes
pojo), the solution is dead simple.

Again, I removed some code, not added! Using Camel really, really shortens
your code.

So, instead of:

@Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
@XmlTransient
private int id;

I did:

@Id
@XmlElement(name = "domain_meteosiId")
 private String id;

and changed database column definition from INT to VARCHAR for the primary
key and the camel jpa component nicely updates my records:


.to("jpa:com.mycompany.model.entities.weather.WeatherCurrent?persistenceUnit=weather")

One more small battle won.

Cheers,
borut

Dne 31. marec 2012 12:14 je Claus Ibsen <cl...@gmail.com> napisal/-a:

> Hi
>
> There is a usePersist option on JPA.
>
> And check the source code of JpaProducer.
> It should call merge, which ought to do an insert or update.
>
> I suggest to check JPA documentation about the requirements for the
> merge operation.
> I would assume somehow you need data in your POJO that can match so
> the JPA knows if its should do a SQL INSERT or SQL UPDATE.
>
>
>
> On Thu, Mar 29, 2012 at 2:09 PM, Borut Bolčina <bo...@gmail.com>
> wrote:
> > Hello,
> >
> > I do not dare to hope there is a one liner in Java DSL using JPA
> component
> > to update records such as:
> >
> > ...
> >
> .to("jpa:my.model.entities.weather.WeatherCurrent?persistenceUnit=weather"&unique=someDbColumn)
> >
> >
> >
> > I am successfully ADDING the records, but I want to update them. Let's
> say
> > there was an imaginary option 'unique' as above , so
> > the underlying machinery could update the record based on given unique db
> > column.
> >
> > But what about now - how is camel solving this pretty much common
> problem?
> >
> > Just to be sure I am clearly explaining things: I will periodically
> produce
> > a set of Weather pojos and one field will hold an id and based on this id
> > which is also in the corresponding db table (not primary key), the data
> > should be updated (overwritten).
> >
> > -borut
>
>
>
> --
> Claus Ibsen
> -----------------
> CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.blogspot.com/
> Author of Camel in Action: http://www.manning.com/ibsen/
>